0

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

Matthew Whittenham
  • 121
  • 1
  • 1
  • 7

1 Answers1

-1

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>
</style>

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:

<resources>

  <!-- 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>

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

</resources>

(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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491