user1644002
user1644002

Reputation:

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

Upvotes: 506

Views: 241871

Answers (20)

Abdul Basit Rishi
Abdul Basit Rishi

Reputation: 2425

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

Upvotes: 35

Native_Mobile_Arch_Dev
Native_Mobile_Arch_Dev

Reputation: 777

Another programmatic Kotlin Alternative:

mButton.transformationMethod = null

Upvotes: 0

Amirhossein Ghasemi
Amirhossein Ghasemi

Reputation: 22138

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

Upvotes: 21

Reyaz Ahmad
Reyaz Ahmad

Reputation: 136

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"

Upvotes: 2

Nikola Despotoski
Nikola Despotoski

Reputation: 50538

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.

Upvotes: 715

miguel
miguel

Reputation: 16580

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>

Upvotes: 179

parsa sarshar
parsa sarshar

Reputation: 391

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 .

Upvotes: 39

user2288580
user2288580

Reputation: 2258

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.

Upvotes: 12

Ashish Chaugule
Ashish Chaugule

Reputation: 1593

add this line in style

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

Upvotes: 62

rajlaxmi_jagdale
rajlaxmi_jagdale

Reputation: 1388

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

Upvotes: 25

chakri Reddy
chakri Reddy

Reputation: 2920

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.

Upvotes: 12

hidro
hidro

Reputation: 12521

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.

Upvotes: 2

Zvi
Zvi

Reputation: 2424

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.

Upvotes: 0

user1644002
user1644002

Reputation:

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

mButton.setTransformationMethod(null);

Upvotes: 112

pedroca
pedroca

Reputation: 1768

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

Upvotes: 23

wisbucky
wisbucky

Reputation: 37797

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.

Upvotes: 10

Bob bobbington
Bob bobbington

Reputation: 1255

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"

Upvotes: 70

Aniruddha K.M
Aniruddha K.M

Reputation: 7511

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.

Upvotes: 6

user1010160
user1010160

Reputation: 465

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)

Upvotes: 3

tharinduNA
tharinduNA

Reputation: 580

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

Upvotes: 33

Related Questions