Xamarin.Forms on Android: How to remove the Uppercase from a button text

If you create a button on Android and write its text in lowercase (“my text”), when you launch the app, you can see that the text is all uppercase (“MY TEXT”).

This is not a bug but the standard style for Android.

Sometimes we prefer to have our text in lowercase so here I’ll show you different methods to do it.

First of all, consider a very easy Page:

If we run the app on Android, we see that the button text will be : “MY TEXT!” all uppercase. Now let’s see how we can make it lowercase:

CUSTOM RENDERERS

First of all, create an empty class MyButton in you PCL/.NetStandard project:

Now we have to replace the Button with MyButton:

The next step is to create the custom render, so inside the Android project, create the class MyButtonRenderer:

It’s very important to add the first line

[assembly: ExportRenderer(typeof(MyButton), typeof(MyButtonRenderer))]

otherwise the Custom Renderer will not work.

If we run the code, we see that now the button text is: “My Text!”.


EDIT THE STYLES.XML FILE

In your Android project open the styles.xml file inside the folder “Resources/values”, it will be something similar to:

To this file add these lines:

so the your styles.xml file will be:

 

 

USE AN EFFECT

In your Android project create the class ButtonEffect:

In your PCL/.NetStandard project create the class ButtonEffect:

Now you need to change your ContentPage to attach the Effect to your button:



Conclusion

We have seen three methods to remove the Uppercase from your Android button:

  • Custom Renderers
  • Styles
  • Effects

All the methods do the same thing so it’s up to you to decide which method to use. Remember that Custom Renderers and Effects are very important in Xamarin so it’s important to understand them very well.

Leave a Reply