locked
BorderRadius / Corner Radius with AppCompat using Forms on a Button RRS feed

  • Question

  • User116742 posted

    Anyone have notice that if you set your app to use FormAppCompartActivity, BorderRadius on Xamarin Forms seems to stop working? I've tried using BorderRadius with higher values (Example: 50) and nothing, the button is still using the same material default appearance.

    Anyone has a workaround to achieve this without removing FormsAppCompatActivity on the Android side

    Tuesday, March 8, 2016 7:23 PM

Answers

  • User57869 posted

    It looks like Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer does not use BorderRadius at all. The old Xamarin.Forms.Platform.Android.ButtonRenderer uses the internal Xamarin.Forms.Platform.Android.ButtonDrawable which does respect it. So you should file a bug on bugzilla (if there is none already) and write a custom renderer until they fix it. Be sure to inherit from Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer and not from Xamarin.Forms.Platform.Android.ButtonRenderer in your renderer.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, March 10, 2016 10:39 AM

All replies

  • User167259 posted

    I haven't had luck using borderradius on my project either on Android. Works well on iOS though. I hadn't thought about it being appcompat related though.

    Wednesday, March 9, 2016 5:21 AM
  • User57869 posted

    It looks like Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer does not use BorderRadius at all. The old Xamarin.Forms.Platform.Android.ButtonRenderer uses the internal Xamarin.Forms.Platform.Android.ButtonDrawable which does respect it. So you should file a bug on bugzilla (if there is none already) and write a custom renderer until they fix it. Be sure to inherit from Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer and not from Xamarin.Forms.Platform.Android.ButtonRenderer in your renderer.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, March 10, 2016 10:39 AM
  • User116742 posted

    I ended using the default appearance (AppCompat Material) for the moment. But I will look the way to make a custom render for this. Thank you @MichaelRumpler & @AlmaJensen.9398

    Tuesday, March 15, 2016 5:05 PM
  • User203448 posted

    this is discussion working for me ---> https://forums.xamarin.com/discussion/56119/after-changing-from-formsapplicationactivity-to-formsappcompatactivity-some-design-is-not-working

    Tuesday, November 1, 2016 2:19 PM
  • User183259 posted

    Campos finally got the answer

    Create a drawable xml with your button style (include corner radius).

    <?xml version="1.0" encoding="UTF-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="@color/primaryDark" /> <corners android:radius="5dp" /> <stroke android:width="0px" android:color="#000000" /> </shape> </item> <item android:state_focused="true" > <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/primaryDark" /> <corners android:radius="5dp" /> <stroke android:width="0px" android:color="#000000" /> </shape> </item> <item > <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/primary" />
    <corners android:radius="5dp" /> <stroke android:width="0px" android:color="#000000" /> </shape> </item>
    </selector>

    Your renderer should to inherit from Xamarin.Forms.Platform.Android.ButtonRenderer Then create a nativeControl, an instance from Android.Widget.Button and set your drawable as background, set Control properties too var nativeControl = new Android.Widget.Button(Context); nativeControl.SetBackground(Resources.GetDrawable(customButton.AndroidStyle)); nativeControl.Text = customButton.Text; nativeControl.Typeface = Control.Typeface; nativeControl.SetTextColor(Xamarin.Forms.Color.White.ToAndroid()); SetNativeControl(nativeControl);

    Now it should work :)

    Wednesday, June 14, 2017 5:37 PM
  • User177302 posted

    @RobertoErnestoJovelBarrera.44 Question, Did you create the new Android.Widget.Button inside the Renderer's constructor, or the OnElementChanged event handler?

    Also, what is the control, 'customButton' in your example? Please explain.

    thank you

    Wednesday, July 12, 2017 7:54 PM
  • User215636 posted

    I have resolve my problem at create renderer Button. J'hérite de class FormsAppCompatActivity in My MainActivity et j'ai créé un ButtonRender qui hérite de Xamarin.Forms.Platform.Android.ButtonRender et non de Xamarin.Forms.Platform.Android.AppCompact. J'ai donc récupéré mes radius

    ``` using CHR.Droid.DependencyService.Renderer; using Xamarin.Forms; using Xamarin.Forms.Platform.Android;

    [assembly: ExportRenderer(typeof(Xamarin.Forms.Button), typeof(MyButtonRenderer))] namespace CHR.Droid.DependencyService.Renderer { public class MyButtonRenderer : ButtonRenderer { public MyButtonRenderer() {

        }
    }
    

    } ```

    Tuesday, September 26, 2017 11:37 AM
  • User215636 posted

    I have resolve my problem to create. I inherited Class FormsAppCompatActivity in My MainActivity and I created a ButtonRender that inherits from Xamarin.Forms.Platform.Android.ButtonRender and not from Xamarin.Forms.Platform.Android.AppCompact. So I recovered my radius

    ``` using CHR.Droid.DependencyService.Renderer; using Xamarin.Forms; using Xamarin.Forms.Platform.Android;

    [assembly: ExportRenderer(typeof(Xamarin.Forms.Button), typeof(MyButtonRenderer))] namespace CHR.Droid.DependencyService.Renderer { public class MyButtonRenderer : ButtonRenderer { public MyButtonRenderer() {

        }
    }
    

    } ```

    Wednesday, September 27, 2017 7:38 AM