locked
Button BorderColor not showing on Android 4.4 RRS feed

  • Question

  • User55444 posted

    The title says it all. My code can be seen below.

        Button mybtt = new Button
            {
                BorderColor = Color.Black,
                BackgroundColor = Color.Transparent,
                IsEnabled = true,
                BorderWidth = 1,
                BorderRadius = 0,
            };
    

    Can someone confirm the issue? There is a way around this problem?

    Wednesday, August 27, 2014 1:41 PM

Answers

  • User154 posted

    FWIW to anyone having this Android button missing border issue, I confirmed it is still an issue in Xamarin.Forms 2 (v2.0.0.6482). I didn't see a bugzilla report, so I filed a bug.

    So, if you have the issue, definitely use the BorderRadius workaround above from @TillBallendat.6136. Here's a C# example of restricting the workaround to Android.

    // HACK: fixes a bug where border doesn't get draw unless there is a radius.
    yourButton.BorderRadius = Device.OnPlatform<int>(iOS: 0, Android: 1, WinPhone: 0);
    

    Here is a XAML example of the same.

    <Button
        x:Name="YourButton"
        Text="Some Button Text"
        TextColor="Black"
        Clicked="OnClickedDiscover"
        BackgroundColor="Aqua"
        BorderColor="Red"
        BorderWidth="1">
        <Button.BorderRadius>
            <!-- HACK: fixes a bug where border doesn't get draw unless there is a radius. -->
            <OnPlatform x:TypeArguments="x:Int32">
                <OnPlatform.Android>1</OnPlatform.Android>
            </OnPlatform>
        </Button.BorderRadius>
    </Button>
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, November 19, 2015 3:54 AM

All replies

  • User81369 posted

    same issue happening with my project, did you find a solution?

    Tuesday, November 4, 2014 9:58 AM
  • User55444 posted

    Nope, not yet. It's not a priority for us so we move on... :/

    Tuesday, November 4, 2014 10:14 AM
  • User91533 posted

    Seems the minimum value for BorderRadius is 1. When using 0 the Button has no border .-(

    Monday, January 19, 2015 1:00 PM
  • User153156 posted

    There is a property called broderWidth. It's default to 0.

    Tuesday, September 15, 2015 2:19 PM
  • User154 posted

    FWIW to anyone having this Android button missing border issue, I confirmed it is still an issue in Xamarin.Forms 2 (v2.0.0.6482). I didn't see a bugzilla report, so I filed a bug.

    So, if you have the issue, definitely use the BorderRadius workaround above from @TillBallendat.6136. Here's a C# example of restricting the workaround to Android.

    // HACK: fixes a bug where border doesn't get draw unless there is a radius.
    yourButton.BorderRadius = Device.OnPlatform<int>(iOS: 0, Android: 1, WinPhone: 0);
    

    Here is a XAML example of the same.

    <Button
        x:Name="YourButton"
        Text="Some Button Text"
        TextColor="Black"
        Clicked="OnClickedDiscover"
        BackgroundColor="Aqua"
        BorderColor="Red"
        BorderWidth="1">
        <Button.BorderRadius>
            <!-- HACK: fixes a bug where border doesn't get draw unless there is a radius. -->
            <OnPlatform x:TypeArguments="x:Int32">
                <OnPlatform.Android>1</OnPlatform.Android>
            </OnPlatform>
        </Button.BorderRadius>
    </Button>
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, November 19, 2015 3:54 AM
  • User260731 posted

    @AdamPatridge Even with border radius android not rendering border

    Forms Version: Xamarin.Forms.2.3.2.127

    Anyone got it working?

    Wednesday, January 25, 2017 7:33 AM
  • User277680 posted

    in Xamarin 2.3.3.180 the bug still exists. the workaround suggested by Adam.Patrige / TillBallendat does not work (for me) .

    tested on android 6.0.1

    i worked around this using a custom renderer

    https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/

    Monday, February 6, 2017 3:39 PM
  • User265278 posted

    Hello developers,

    Here is solution:

    Button:

     Button mybtt = new Button
            {
                BorderColor = Color.Black,
                BackgroundColor = Color.Transparent,
                IsEnabled = true,
                BorderWidth = 1,
                BorderRadius = 2,
            };
    

    Render:

        using Xamarin.Forms.Platform.Android;
        using Xamarin.Forms;
    
        [assembly: ExportRenderer(typeof(Button), typeof(YourNamespace.Droid.FlatButtonRenderer))]
    
        namespace YourNamespace.Droid
        {
            public class FlatButtonRenderer : ButtonRenderer
            {
                protected override void OnDraw(Android.Graphics.Canvas canvas)
                {
                    base.OnDraw(canvas);
                }
    
                protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
                {
                    base.OnElementChanged(e);
                }
            }
        }
    
    Wednesday, March 29, 2017 9:58 AM
  • User333518 posted

    it worked bro.

    Friday, July 14, 2017 2:53 AM
  • User267719 posted

    This should be correct answer:

    "On Android this property will not have an effect unless VisualElement.BackgroundColor is set to a non-default color."

    https://stackoverflow.com/questions/31930478/xamarin-forms-button-with-no-border-issue

    Tuesday, July 18, 2017 2:37 PM
  • User155041 posted

    @Angelru9 said: Hello developers,

    Here is solution:

    Button:

     Button mybtt = new Button
            {
                BorderColor = Color.Black,
                BackgroundColor = Color.Transparent,
                IsEnabled = true,
                BorderWidth = 1,
                BorderRadius = 2,
            };
    

    Render:

        using Xamarin.Forms.Platform.Android;
        using Xamarin.Forms;
    
        [assembly: ExportRenderer(typeof(Button), typeof(YourNamespace.Droid.FlatButtonRenderer))]
    
        namespace YourNamespace.Droid
        {
            public class FlatButtonRenderer : ButtonRenderer
            {
                protected override void OnDraw(Android.Graphics.Canvas canvas)
                {
                    base.OnDraw(canvas);
                }
    
                protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
                {
                    base.OnElementChanged(e);
                }
            }
        }
    

    Thank you so much it worked , dont know why a renderer is really required

    Wednesday, January 31, 2018 11:25 AM
  • User270940 posted

    Oh my god why is adding a renderer that just does the same thing as the ButtonRenderer fix this issue? Thanks @Angelru9 ... I think this should be tagged as a possible answer imo

    Monday, May 14, 2018 7:03 AM
  • User399435 posted

    *Try this *

    Friday, February 19, 2021 11:16 PM
  • User399435 posted

    Try this

    Friday, February 19, 2021 11:16 PM