async Task BuildBackground()
{
using (var statesBackground = new StateListDrawable ()) {
if (BaseElement.NormalImage != null) {
var normalHandler = BaseElement.NormalImage.GetHandler ();
using (var imgNormal = await normalHandler.LoadImageAsync (BaseElement.NormalImage, base.Context)) {
statesBackground.AddState (
new int[]{
-global::Android.Resource.Attribute.StatePressed,
global::Android.Resource.Attribute.StateEnabled
},
new BitmapDrawable(imgNormal)
);
if (BaseElement.PressedImage == null) {
statesBackground.AddState (
new int[] {
global::Android.Resource.Attribute.StatePressed,
global::Android.Resource.Attribute.StateEnabled
},
new BitmapDrawable(imgNormal)
);
}
if (BaseElement.DisableImage == null) {
statesBackground.AddState (
new int[] {
-global::Android.Resource.Attribute.StateEnabled
},
new BitmapDrawable(imgNormal)
);
}
}
}
if (BaseElement.PressedImage != null) {
var pressedHandler = BaseElement.PressedImage.GetHandler ();
using (var imgPressed = await pressedHandler.LoadImageAsync (BaseElement.PressedImage, base.Context)) {
statesBackground.AddState (
new int[] {
global::Android.Resource.Attribute.StatePressed,
global::Android.Resource.Attribute.StateEnabled
},
new BitmapDrawable(imgPressed)
);
}
}
if (BaseElement.DisableImage != null) {
var disableHandler = BaseElement.DisableImage.GetHandler ();
using (var imgDisable = await disableHandler.LoadImageAsync (BaseElement.DisableImage, base.Context)) {
statesBackground.AddState (
new int[] {
-global::Android.Resource.Attribute.StateEnabled
},
new BitmapDrawable(imgDisable)
);
}
}
if (Control != null)
Control.Background = statesBackground;
}
}