Button on Android all caps

I have just noticed that on Xamarin Forms Android, the text label on elements appears in ALL CAPS. Is this by design?

Regards,
Ian

Posts

  • CraigDunnCraigDunn USXamarin Team Xamurai

    @IanDuncanson yeah, Android defaults to this for certain controls, and Xamarin.Forms always tries to honor platform defaults.

  • RameshVPRameshVP USMember
    edited April 2015

    @BrandonLi Thanks.Is it default Android behaviour? I dont think so

  • BrandonLiBrandonLi USMember

    @RameshVP You're right, all caps is default Android behavior, but above is an exposed API for cases where you would want to override that behavior

  • PeterMajor.5288PeterMajor.5288 GBMember, University ✭✭

    For our app, the caps in the button was only a problem when using the material design style.

  • Vikram_BVikram_B USMember ✭✭

    Hi Guys,

    I am facing the same issue in Xamarin forms cs file in Xamarin studio.

    my code snippet is below.

    var button = new Button { Text = "Login" , BackgroundColor = Color.Red , TextColor = Color.White , FontFamily = "Verdana"};
            button.BorderRadius = 20;
            button.TextColor = Color.White;
            button.WidthRequest =240;
            button.HeightRequest = 50;
    

    When I run my program it is button with "LOGIN" text on it.

    but I didnt give like that

  • VanCarlNguyenVanCarlNguyen SEMember ✭✭

    MyButton.cs

    public class MyButton : Button { }

    MyButtonRenderer.cs

    public class MyButtonRenderer : ButtonRenderer { protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e) { base.OnElementChanged(e); var button = this.Control; button.SetAllCaps(false); } }

    @BrandonLi Thanks!

  • Sreeraj.0276Sreeraj.0276 USMember ✭✭
    edited July 2016

    @PeterMajor.5288 said:
    You could also just put this in your Android styles.xml:

    > @style/MyTextAppearance.Material.Button >

    > false > false >

    Standard solution.

  • SuchithSuchith INMember ✭✭✭

    Any solution without using renderer , and styles.xml is not reflecting any changes to form control

  • rogiheerogihee NLMember ✭✭✭

    You can also an effect for that:

    [assembly: ExportEffect (typeof (ButtonNotAllCapsEffect), nameof (ButtonNotAllCapsEffect))]
    namespace _myEffects.Effects
    {
        public class ButtonNotAllCapsEffect : PlatformEffect
        {
            protected override void OnAttached ()
            {
                try {
                    var control = Control as Android.Widget.Button;
                    control.SetAllCaps (false);
    
                } catch (Exception ex) {
                    Console.WriteLine ("Cannot set property on attached control. Error: ", ex.Message);
                }
            }
    
            protected override void OnDetached ()
            {
            }
    
            protected override void OnElementPropertyChanged (System.ComponentModel.PropertyChangedEventArgs args)
            {
                base.OnElementPropertyChanged (args);
            }
        }
    }
    
  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    @rogihee said:
    You can also an effect for that:

    [assembly: ExportEffect (typeof (ButtonNotAllCapsEffect), nameof (ButtonNotAllCapsEffect))]
    namespace _myEffects.Effects
    {
        public class ButtonNotAllCapsEffect : PlatformEffect
        {
            protected override void OnAttached ()
            {
                try {
                    var control = Control as Android.Widget.Button;
                    control.SetAllCaps (false);
    
                } catch (Exception ex) {
                    Console.WriteLine ("Cannot set property on attached control. Error: ", ex.Message);
                }
            }
    
            protected override void OnDetached ()
            {
            }
    
            protected override void OnElementPropertyChanged (System.ComponentModel.PropertyChangedEventArgs args)
            {
                base.OnElementPropertyChanged (args);
            }
        }
    }
    

    you could contribute to https://github.com/FormsCommunityToolkit/Effects

  • Vaka.GopiNadhReddyVaka.GopiNadhReddy USMember ✭✭✭

    public class CustomButtonRender : ButtonRenderer
    {
    protected override void OnElementChanged(ElementChangedEventArgs e)
    {
    base.OnElementChanged(e);
    var button = this.Control;
    button.SetAllCaps(false);
    }

        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
        }
    
    }
    
  • 15mgm1515mgm15 USMember ✭✭✭✭

    Does anyone has a solution for the ToolBarItems buttons?

  • Liêm_NguyễnLiêm_Nguyễn USMember ✭✭✭✭

    Solved by adding the following to your styles.xml file which can be found in the Android project under the Resources then values folders.

     <item name="android:textAllCaps">false</item>
    
Sign In or Register to comment.