Matthew Whittenham Matthew Whittenham - 1 year ago 113
Android Question

How do I include lowercase characters in the text on a button using Android API 10?

I am trying to get a mixture of lower & uppercase text on a button (rather than just the default upper case only) on Android Studio. I am aware I can use 'android:textAllCaps="false"', but this is only available for API 14 and above. Is there a way around this which I can use for API 10? Thanks

Answer Source

Step #1: Open app/src/main/res/values/styles.xml. This should show a stub custom theme, inheriting from a Theme.AppCompat-based theme, given your symptoms.

Step #2: Add a new <style> to that file:

<style name="MixedCaseButton" parent="Widget.AppCompat.Button">
  <item name="textAllCaps">false</item>

You will notice that this references textAllCaps. The native implementation of textAllCaps is new to API Level 14. This theme is using the backport of textAllCaps supplied by appcompat-v7, which you are using, given your symptoms.

Step #3: Add this element to your custom theme, the one that already existed in the styles.xml file:

<item name="buttonStyle">@style/MixedCaseButton</item>

This will give you an overall styles.xml file resembling:


  <!-- Base application theme. -->
  <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="buttonStyle">@style/MixedCaseButton</item>

  <style name="MixedCaseButton" parent="Widget.AppCompat.Button">
    <item name="textAllCaps">false</item>


(though the other contents of the pre-existing style resource may vary somewhat)

Step #4: Run your app, and you will see the button appear in mixed case. Please note that this violates the Material Design aesthetic.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download