Why is my Button text forced to ALL CAPS on Lollipop?
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:
Use
android:textAllCaps="false"
in yourlayout-v21
Programmatically change the transformation method of the button.
mButton.setTransformationMethod(null);
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>
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, 2020Comments
-
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 over 9 years#1 made no difference. Not sure how to do #3, have no styles? Now trying #2.
-
user1644002 over 9 yearsyes, adding this: btn[i].setTransformationMethod(null); makes it work thanks
-
user1644002 over 9 yearsI 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 over 9 yearsThat's great to know. If there a site which lists all of these defaulted values per android version?
-
patrickjason91 about 9 yearsWorked for me too, used the programmatical method since textAllCaps XML attr is only supported API > 14. thanks!
-
paulgavrikov about 9 yearsThat 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 over 8 yearsI used
<item name="android:textAllCaps">false</item>
in my style definition -
Someone Somewhere over 8 yearsI agree, it's great to follow design guidelines... until the button text no longer fits in the button
-
Vfleitao over 8 yearsWorked 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 about 8 yearsI DON'T KNOW WHY THEY'D MAKE THIS THE DEFAULT
-
QAMAR about 8 yearsThis is default in material theme, as it suits nature of material design
-
bharal over 7 yearsgoogle 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 over 7 yearsFor pre-API Level 14 support, you can use
<item name="textAllCaps">false</item>
. -
user3833732 almost 7 yearsVery reluctantly i tried #2, And it was a mind boggling SUCCESS!!
-
Bimde almost 7 years1. Works perfectly when adding it to the button's xml directly
-
user2808624 over 6 yearsThis 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 over 6 yearsDidn't work for me. Became to work when I changed
buttonStyle
toandroid:buttonStyle
-
meyasir almost 6 yearsIn XML
android:textAllCaps="false"
(I'm Using android studio 3.0) -
eric almost 5 yearspoor people stuck in the square box of material design
-
Native_Mobile_Arch_Dev over 4 yearsFor Kotlin, the syntax is: mButton.transformationMethod = null
-
Nagaraj Alagusundaram over 3 yearsToday I faced this and I also confirm that this solution works.
-
Yi Xiang Chong about 3 yearsVery useful answer. Thank you