I\'m trying to create a custom ButtonRenderer for Xamarin.Forms. Here is a simple test I\'ve been trying to put up together following some tutorials, but I can\'s seem to ma
replace CustomButtonRenderer code to below code.
[assembly: ExportRenderer(typeof(Xamarin.Forms.Button), typeof(CustomButtonRenderer))]
namespace TestProject.Droid.CustomRenderers
{
public class CustomButtonRenderer: ButtonRenderer
{
public CustomButtonRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
return;
}
var nativeButton = (Android.Widget.Button)this.Control;
nativeButton.SetBackgroundColor(Android.Graphics.Color.Gray);
}
}
}
I'm still investigating on this. Your class gets shrunk because it's not statically linked in your PCL. You avoid that by giving a name to your classes like this:
[Activity(Name = "somepackage.custombuttonrenderer")]
public class CustomButtonRenderer: ButtonRenderer
{ }
If you're able to target the minimum Android version to Android 5.0 (Api 21) this problem should disappear as another version of the Dex file is used.