Segamoto
Segamoto

Reputation: 315

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

Upvotes: 4

Views: 7388

Answers (4)

balintn
balintn

Reputation: 1453

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" />

Upvotes: 2

Prasanth Raj
Prasanth Raj

Reputation: 167

I faced similar issue where I have specified the border color property alone. Looks like by default the border width is zero therefore the button border was not shown. After updating border width, it works fine.

Upvotes: 0

Nico Zhu
Nico Zhu

Reputation: 32785

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.

Upvotes: 3

Mr.Ko&#231;ak
Mr.Ko&#231;ak

Reputation: 333

I have Samsung s3 (API 19,Android 4.4 Kitkat). This does actually work on my phone

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="MyProject.MyPage" BackgroundColor = "White">
    <ContentPage.Content>
        <StackLayout Orientation = "Vertical" BackgroundColor = "White">

            <Button 
                Text="Test" 
                BorderWidth="10" 
                BorderRadius="5" 
                BorderColor="Red"
                    TextColor = "Black"
                    VerticalOptions = "Start"
                    HorizontalOptions = "Fill"
                BackgroundColor = "White">
            </Button>
        </StackLayout> 


    </ContentPage.Content>
</ContentPage>

In cs file

MyPage()
{
InitializeComponent();
}

Hope it helps

Upvotes: 0

Related Questions