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

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

The answer is


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 .


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

Add android:textAllCaps="false" in <Button> tag that's it.


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>

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"


Another programmatic Kotlin Alternative:

mButton.transformationMethod = null


Lollipop default comes with "textAllCaps true", so you have to manually make it to false


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.


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.


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)


add this line in style

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


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.


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


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.


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"

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.


If you use appcompat-v7, you can subclass AppCompatButtonand 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.


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"
      .
      .
   />

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.


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to android-5.0-lollipop

Android changing Floating Action Button color Android Support Design TabLayout: Gravity Center and Mode Scrollable Android statusbar icons color Notification bar icon turns white in Android 5 Lollipop How can I change default dialog button text color in android 5 Lollipop : draw behind statusBar with its color set to transparent Android lollipop change navigation bar color CardView not showing Shadow in Android L App crashing when trying to use RecyclerView on android 5.0 How to change status bar color to match app in Lollipop? [Android]

Examples related to android-button

How to change the color of a button? Why is my Button text forced to ALL CAPS on Lollipop? Coloring Buttons in Android with Material Design and AppCompat Android Material Design Button Styles How to custom switch button? Android button with icon and text Android Fragment onClick button Method How do I open a new fragment from another fragment? Change Screen Orientation programmatically using a Button Android button background color

Examples related to android-styles

How to change the style of a DatePicker in android? Android statusbar icons color How to set Toolbar text and back arrow color Why is my Button text forced to ALL CAPS on Lollipop? How to change color of the back arrow in the new material theme? Changing EditText bottom line color with appcompat v7 Android toolbar center title and custom font How to custom switch button? Style bottom Line in Android AlertDialog styling - how to change style (color) of title, message, etc