It seems that the BorderRadius attribute is not working when including AppCompat in the project.
I tried to create a custom render like this discussed here, but it didn't work:
namespace Xamarin.Forms
{
public class CustomButton : Button
{
public CustomButton():base()
{
}
protected override void OnParentSet()
{
base.OnParentSet();
}
}
}
In the Android project:
[assembly: ExportRenderer(typeof(CustomButton), typeof(CustomButtonRenderer))]
namespace CalculateurMadelin.Droid.Renderers
{
public class CustomButtonRenderer : Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer
{ }
}
You can load an Android drawable
in your custom renderer to define the background on your AppCompat.Button
:
[assembly: ExportRenderer(typeof(CustomButton), typeof(CustomButtonRenderer))]
namespace AppCompatRender.Droid
{
public class CustomButtonRenderer : Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
Control.SetBackgroundResource(Resource.Drawable.CustomButtonBackground);
}
}
}
}
Add a new Resources/Drawable
that matches the name you are using in your SetBackgroundResource
(i.e.. CustomButtonBackground.axml
), in this I am setting a corner radius of the rectangle as 10dp
:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
</shape>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With