466

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

Community
  • 1
  • 1
user1644002
  • 3,431
  • 3
  • 14
  • 18

20 Answers20

666

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.

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
Nikola Despotoski
  • 46,951
  • 13
  • 114
  • 146
172

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>
miguel
  • 14,055
  • 4
  • 48
  • 53
  • 8
    For pre-API Level 14 support, you can use `false`. – CommonsWare Nov 25 '16 at 22:10
  • This applies only to Widget.AppCompat.Button. The more general answer is given by Ashish Chaugule below, i.e. adding directly false 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.) – user2808624 Jan 07 '18 at 11:35
  • 1
    Didn't work for me. Became to work when I changed `buttonStyle` to `android:buttonStyle` – Vasily Kabunov Jan 21 '18 at 15:09
  • 2
    In XML `android:textAllCaps="false"` (I'm Using android studio 3.0) – meyasir Jul 31 '18 at 10:45
110

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

mButton.setTransformationMethod(null);
rAinmAker
  • 3
  • 2
user1644002
  • 3,431
  • 3
  • 14
  • 18
68

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"
Bob bobbington
  • 1,080
  • 11
  • 10
60

add this line in style

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

Ashish Chaugule
  • 1,319
  • 8
  • 8
38

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 .

parsa sarshar
  • 381
  • 3
  • 2
33

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

tharinduNA
  • 580
  • 5
  • 12
  • 6
    That's great to know. If there a site which lists all of these defaulted values per android version? – Adam Jan 08 '15 at 18:05
25

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

Mr Lister
  • 42,557
  • 14
  • 95
  • 136
rajlaxmi_jagdale
  • 1,170
  • 13
  • 16
25

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"
           />
Abdul Basit Rishi
  • 872
  • 14
  • 19
20

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

pedroca
  • 1,578
  • 1
  • 16
  • 17
  • 2
    I agree, it's great to follow design guidelines... until the button text no longer fits in the button – Someone Somewhere Sep 28 '15 at 11:24
  • 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! – bharal Nov 02 '16 at 17:55
17

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"
      .
      .
   />
Amir Hossein Ghasemi
  • 7,952
  • 4
  • 43
  • 42
12

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.

chakri Reddy
  • 2,900
  • 1
  • 13
  • 12
12

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.

user2288580
  • 1,798
  • 17
  • 14
10

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.

wisbucky
  • 22,510
  • 8
  • 103
  • 76
4

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.

Mightian
  • 6,853
  • 3
  • 37
  • 50
2

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)

user1010160
  • 416
  • 3
  • 9
  • 4
    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. – paulgavrikov Mar 14 '15 at 21:30
2

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.

hidro
  • 11,509
  • 5
  • 49
  • 53
2

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"

Shalu T D
  • 3,373
  • 2
  • 21
  • 32
0

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.

Zvi
  • 1,858
  • 2
  • 19
  • 32
0

Another programmatic Kotlin Alternative:

mButton.transformationMethod = null