Why is my Button text forced to ALL CAPS on Lollipop?
AndroidAndroid 5.0-LollipopAndroid ButtonAndroid StylesAndroid Problem Overview
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
Android Solutions
Solution 1 - Android
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 2 - Android
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 3 - Android
This is fixable in the application code by setting the button's TransformationMethod, e.g.
mButton.setTransformationMethod(null);
Solution 4 - Android
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 - Android
add this line in style
<item name="android:textAllCaps">false</item>
Solution 6 - Android
this one is working .... just in your code in your bottom code add this one :
android:textAllCaps="false"
it should deactivate the caps letter that U trying to type small .
Solution 7 - Android
Lollipop default comes with "textAllCaps true", so you have to manually make it to false
Solution 8 - Android
Use this line android:textAllCaps="false" in your xml
<Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/login_str"
android:background="@color/colorBlue"
android:textColor="@color/colorWhite"
android:textAllCaps="false"
/>
Solution 9 - Android
Add android:textAllCaps="false" in <Button>
tag that's it.
Solution 10 - Android
There is an easier way which works for all buttons, just change appearance of buttons in your theme, try this:
in values-21/styles.xml
<resources>
<style name="myBaseTheme"
parent="@android:style/Theme.Material.Light">
<item name="android:colorPrimary">@color/bg</item>
<item name="android:colorPrimaryDark">@color/bg_p</item>
<item name="android:textAppearanceButton">@style/textAppearanceButton</item>
</style>
<style name="textAppearanceButton" parent="@android:style/TextAppearance.Material.Widget.Button">
<item name="android:textAllCaps">false</item>
</style>
</resources>
PS: it's recommended to follow material design's principles, you should show capitalized text in Buttons, http://www.google.com/design/spec/components/buttons.html
Solution 11 - Android
Java:
yourButton.setAllCaps(false);
Kotlin:
yourButton.isAllCaps = false
XML:
android:textAllCaps="false"
Styles:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="buttonStyle">@style/yourButtonStyle</item>
</style>
<style name="yourButtonStyle" parent="Widget.AppCompat.Button">
<item name="android:textAllCaps">false</item>
</style>
In layout:
<Button
.
.
style="@style/yourButtonStyle"
.
.
/>
Solution 12 - Android
You could add android:textAllCaps="false"
to the button.
The button text might be transformed to uppercase by your app's theme that applies to all buttons. Check themes / styles files for setting the attribute android:textAllCaps
.
Solution 13 - Android
Using the android.support.v7.widget.AppCompatButton in the XML layout will allow you to avoid having to have a layout-21 or programmatically changing anything. Naturally this will also work with AppCompat v7 library.
<android.support.v7.widget.AppCompatButton
android:id="@+id/btnOpenMainDemo"
android:textAllCaps="false"
style="@style/HGButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_main_demo"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
Hope this helps.
Solution 14 - Android
In Android Studio IDE, you have to click the Filter icon to show expert properties. Then you will see the textAllCaps
property. Check it, then uncheck it.
Solution 15 - Android
If you have arrived here because your facebook button text appears in all caps then just add this android:textAllCaps="false"
in your xml file. It worked for me.
Solution 16 - Android
OK, just ran into this. Buttons in Lollipop come out all uppercase AND the font resets to 'normal'. But in my case (Android 5.02) it was working in one layout correctly, but not another!?
Changing APIs didn't work.
Setting to all caps requires min API 14 and the font still resets to 'normal'.
It's because the Android Material Styles forces a change to the styles if there isn't one defined (that's why it worked in one of my layout and not the other because I defined a style).
So the easy fix is to define a style in the manifest for each activity which in my case was just:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
(hope this helps someone, would have saved me a couple of hours last night)
Solution 17 - Android
If you use appcompat-v7
, you can subclass AppCompatButton
and setSupportAllCaps(false)
, then use this class for all your buttons.
/**
* Light extension of {@link AppCompatButton} that overrides ALL CAPS transformation
*/
public class Button extends AppCompatButton {
public Button(Context context, AttributeSet attrs) {
super(context, attrs);
setSupportAllCaps(false);
}
public Button(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setSupportAllCaps(false);
}
}
See AppCompatButton#setSupportAllCaps(boolean) Android docs.
Solution 18 - Android
By default, Button in android provides all caps keyword. If you want button text to be in lower case or mixed case you can disable textAllCaps
flag using android:textAllCaps="false"
Solution 19 - Android
I do not know why the answer of @user1010160 got rating of 0. I would have given it +1 if I had enough reputations.
Since my app is designed for API less than 14 and I did not want to add code to my program I did not find a solution until I read his answer. What he said was that even though you have done what is needed in the Application styles it will not work unless you add a style to your activity and there you set textAllCaps to false.
It is not enough to have a style for the activity (my activity had a style), because the style might defaults to the AllCaps property. You have to set explicitly, in the activity too, that property to false.
I now have it both in the Application and in the Activity parts of the manifest file.
Solution 20 - Android
Another programmatic Kotlin Alternative:
mButton.transformationMethod = null