Cannot lower case button text in android studio

AndroidButtonAndroid Studio

Android Problem Overview


I have a trivial question that has been bothering me for a while. I tried to google this but no one seems to have the same problem as me or doesn't see it as an issue. When I make a button in activity_my.xml under layout

 <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_1_name"
    android:id="@+id/button2"
    android:layout_marginTop="140dp"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true" />

I get a button that looks like ![this]Imgur

even though my strings code is:

<resources>

<string name="app_name">HelloWorld</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="button_1_name">BuTtOn 1</string>

I know I am definitely missing something small here, but how do I get lower case/upper case working in the button text?

Thanks!

Android Solutions


Solution 1 - 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 2 - Android

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:buttonStyle">@style/Button</item>
</style>

<style name="Button" 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 null, e.g.

mButton.setTransformationMethod(null);

Solution 4 - Android

add android:textAllCaps="false" in xml button It's true with this issue.

Solution 5 - Android

there are 3 ways to do it.

1.Add the following line on style.xml to change entire application

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

2.Use

android:textAllCaps="false"

in your layout-v21

mButton.setTransformationMethod(null);

3. add this line under the element(button or edit text) in xml

> android:textAllCaps="false"

regards

Solution 6 - Android

You could set like this

button.setAllCaps(false);

programmatically

Solution 7 - Android

In your .xml file within Button add this line--

android:textAllCaps="false"

Solution 8 - Android

It can be done easily by using the following code inside your view in activity_main.xml:

android:textAllCaps="false"

In your case it would be as follows:

 <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_1_name"
android:id="@+id/button2"
android:layout_marginTop="140dp"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:textAllCaps="false" />

You can also change it for all the buttons in your app by adding this to your styles/themes.xml:

<style name="AppTheme" parent="AppBaseTheme">
<item name="android:buttonStyle">@style/Button</item>
</style>

<style name="Button" parent="Widget.AppCompat.Button">
<item name="android:textAllCaps">false</item>
</style>

It can also be set Programatically by using the following in mainActivity.kt or mainActivity.java:

Button btn = (Button) findViewById(R.id.button2);
btn.setAllCaps(false);

Solution 9 - Android

in XML Code
add this line android:textAllCaps="false" like bellow code

 <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_1_name"
        android:id="@+id/button2"
        android:layout_marginTop="140dp"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true"
       ** android:textAllCaps="false" ** />

or

in Java code (programmatically)
add this line to your button setAllCaps(false)

Button btn = (Button) findViewById(R.id.button2);
btn.setAllCaps(false);

Solution 10 - Android

There is a property in <Button> that is android:textAllCaps="false" that make characters in which you want in your own Small and caps. By Default its became True so write this code and make textAllCaps=false then you can write text on button in small and Caps letter as per your requirement. Complete code for a Button which allow use to write letters as per our requirement.

 <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/btnLogin"
            android:text="Login for Chat"
            android:textAllCaps="false"/>

Solution 11 - Android

I have faced this issue in TextView. I have tried

android:textAllCaps="false", 
mbutton.setAllCaps(false);   
<item name="android:textAllCaps">false</item> 

none of that worked for me. Finally I fed up and I have hard coded text, it is working.

tv.setText("Mytext");

tv is object of TextView. But as per coding standards, it is bad practice.

Solution 12 - Android

in XML: android:textAllCaps="false"

Programmatically:

mbutton.setAllCaps(false);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlex HView Question on Stackoverflow
Solution 1 - AndroidStelian MateiView Answer on Stackoverflow
Solution 2 - AndroidChanghoonView Answer on Stackoverflow
Solution 3 - AndroidAttaullahView Answer on Stackoverflow
Solution 4 - AndroidHai RomView Answer on Stackoverflow
Solution 5 - AndroidDinithe PierisView Answer on Stackoverflow
Solution 6 - AndroidmissionManView Answer on Stackoverflow
Solution 7 - AndroidPAWAN LAKHOTIAView Answer on Stackoverflow
Solution 8 - AndroidShaurya GoyalView Answer on Stackoverflow
Solution 9 - AndroidVasinda View Answer on Stackoverflow
Solution 10 - AndroidPradeep SheoranView Answer on Stackoverflow
Solution 11 - AndroidThirumalvalavanView Answer on Stackoverflow
Solution 12 - AndroidNull Pointer ExceptionView Answer on Stackoverflow