Why is my Button text forced to ALL CAPS on Lollipop?

220,095

Solution 1

This is fixable in the application code by setting the button's TransformationMethod, e.g.

mButton.setTransformationMethod(null);

Solution 2

I don't have idea why it is happening but there 3 trivial attempts to make:

  1. Use android:textAllCaps="false" in your layout-v21

  2. Programmatically change the transformation method of the button. mButton.setTransformationMethod(null);

  3. Check your style for Allcaps

Note: public void setAllCaps(boolean allCaps), android:textAllCaps are available from API version 14.

Solution 3

Here's what I did in my values/themes.xml

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="buttonStyle">@style/MyButton</item>
    </style>

    <style name="MyButton" parent="Widget.AppCompat.Button">
        <item name="android:textAllCaps">false</item>
    </style>

Solution 4

Set android:textAllCaps="false". If you are using an appcompat style, make sure textAllCaps comes before the style. Otherwise the style will override it. For example:

android:textAllCaps="false"
style="@style/Base.TextAppearance.AppCompat"

Solution 5

add this line in style

    <item name="android:textAllCaps">false</item>

Share:
220,095
user1644002
Author by

user1644002

I am a retired electrical engineer, worked at Intel for 28 years doing test development and hardware and firmware design. Now I am working on tide prediction and presentation apps and the occasional website.

Updated on December 07, 2020

Comments

  • user1644002
    user1644002 over 3 years

    In my app "Tide Now WA" which I recently tested for compatibility using the new Nexus 9 tablet (Lollipop - API 21).

    It writes some button text. This app writes the text correctly using Android 2.3 and Android 4.0. I.e. mixed capital and lower case letters.

    When same app is run on my Nexus 9 all the letters in the text are capitalized.

    FWIW my manifest contains the following statement:

    uses-sdk android:minSdkVersion="10" android:targetSdkVersion="14"

    Can I fix this in my code or is it a bug in the O.S. thanks

  • user1644002
    user1644002 over 9 years
    #1 made no difference. Not sure how to do #3, have no styles? Now trying #2.
  • user1644002
    user1644002 over 9 years
    yes, adding this: btn[i].setTransformationMethod(null); makes it work thanks
  • user1644002
    user1644002 over 9 years
    I am accepting Nikola's answer as the solution, but want to point out the other part of the questions is that as provided by alanv, who explained the why in the comments above.
  • Adam
    Adam over 9 years
    That's great to know. If there a site which lists all of these defaulted values per android version?
  • patrickjason91
    patrickjason91 about 9 years
    Worked for me too, used the programmatical method since textAllCaps XML attr is only supported API > 14. thanks!
  • paulgavrikov
    paulgavrikov about 9 years
    That is a very bad attempt, just create styles for your buttons, one in values-21 that has allCaps false. Falling back to an older theme (here a Holo Theme) makes your app uglier and more inconsistent to the user.
  • Someone Somewhere
    Someone Somewhere over 8 years
    I used <item name="android:textAllCaps">false</item> in my style definition
  • Someone Somewhere
    Someone Somewhere over 8 years
    I agree, it's great to follow design guidelines... until the button text no longer fits in the button
  • Vfleitao
    Vfleitao over 8 years
    Worked like a charm but on my case I had to do like: <style name="textAppearanceButton" parent="@android:style/TextAppearance.Material.Widget.Button‌​"> <item name="android:textAllCaps">false</item> </style>
  • Glenn Maynard
    Glenn Maynard about 8 years
    I DON'T KNOW WHY THEY'D MAKE THIS THE DEFAULT
  • QAMAR
    QAMAR about 8 years
    This is default in material theme, as it suits nature of material design
  • bharal
    bharal over 7 years
    google should just stop talking about styles - i wasn't aware that there were ppl crying and sobbing in the streets because of lowercase buttons!
  • CommonsWare
    CommonsWare over 7 years
    For pre-API Level 14 support, you can use <item name="textAllCaps">false</item>.
  • user3833732
    user3833732 almost 7 years
    Very reluctantly i tried #2, And it was a mind boggling SUCCESS!!
  • Bimde
    Bimde almost 7 years
    1. Works perfectly when adding it to the button's xml directly
  • user2808624
    user2808624 over 6 years
    This applies only to Widget.AppCompat.Button. The more general answer is given by Ashish Chaugule below, i.e. adding directly <item name="android:textAllCaps">false</item> to the theme-style. (Although the questions was originally asked especially for buttons, I think if allCaps is not wanted for buttons, it is also not wanted for menu-items, actions, etc.)
  • Vasily Kabunov
    Vasily Kabunov over 6 years
    Didn't work for me. Became to work when I changed buttonStyle to android:buttonStyle
  • meyasir
    meyasir almost 6 years
    In XML android:textAllCaps="false" (I'm Using android studio 3.0)
  • eric
    eric almost 5 years
    poor people stuck in the square box of material design
  • Native_Mobile_Arch_Dev
    Native_Mobile_Arch_Dev over 4 years
    For Kotlin, the syntax is: mButton.transformationMethod = null
  • Nagaraj Alagusundaram
    Nagaraj Alagusundaram over 3 years
    Today I faced this and I also confirm that this solution works.
  • Yi Xiang Chong
    Yi Xiang Chong about 3 years
    Very useful answer. Thank you