Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button border color xamarin forms not showed

I want to set border color to button in Xamarin Forms but with this code doesn't work:

<Button Text="Test" 
        BorderWidth="5" 
        BorderRadius="2" 
        BorderColor="Red">
</Button>

Using this code the border doesn't appear.

I've also tried this but doen't work.

I've tried it in Android 4.4 (Phisical Device) and in Android 6.0 (Virtual Device) but doesn't work too.

SOLVED FOLLOWING THIS

like image 523
Segamoto Avatar asked Sep 12 '25 06:09

Segamoto


2 Answers

There are two BottonRenderers in Xamarin Android.

  1. ButtonRenderer under Xamarin.Forms.Platform.Android.AppCompat namespace.

  2. ButtonRenderer under Xamarin.Forms.Platform.Android namespace.

The BottonRenderer did not achieve drawing button border where under Xamarin.Forms.Platform.Android.AppCompat namesapce.

The MainActivity is inherited FormsAppCompatActivity rather than FormsApplicationActivity where is used in android project by default. So the renderer is under Xamarin.Forms.Platform.Android.AppCompat namesapce. But it did not achieve drawing button border. If you want draw button border, you can custom render by using Xamarin.Forms.Platform.Android namesapce.

like image 82
Nico Zhu - MSFT Avatar answered Sep 13 '25 19:09

Nico Zhu - MSFT


By default the border width is zero, so setting its color makes no difference. You need to set both of them:

<Button Text="Jenson" BorderColor="Red" BorderWidth="1" />
like image 31
balintn Avatar answered Sep 13 '25 19:09

balintn