How to Change Button Text to Lower Case from ALL CAP in Android

When you add a button view in XML layout file with text, the button text in android will be ALL CAP.

To change button text to lower case from ALL CAP in android, below is two ways we can achieve android button lower case text.

In XML layout file

Android Button has a textAllCaps attribute android:textAllCaps="true"which is set to true by default. This is the main reason why all text added to android button capitalizes its text content.

To change this is simply to set the android:textAllCaps = "false".

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="24dp"
    android:gravity="center"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorAccent"
        android:text="Lower case button"
        android:textAllCaps="false"
        android:textColor="@color/colorWhite"
        android:textStyle="bold"
        android:textSize="15sp"/>

</androidx.appcompat.widget.LinearLayoutCompat>

Change Button Text to Lower Case Programmatically

Like in XML layout we used the button attribute textAllCapsto change text to lower case. Programmatically, we will use the setAllCaps()method of the Button class as shown below.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="24dp"
    android:gravity="center"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorAccent"
        android:textColor="@color/colorWhite"
        android:textStyle="bold"
        android:textSize="15sp"/>

</androidx.appcompat.widget.LinearLayoutCompat>

MainActivity.java

import android.os.Bundle;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getSimpleName();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button buttonEffect = (Button)findViewById(R.id.button);
        buttonEffect.setText(R.string.main_button);
        buttonEffect.setAllCaps(false);

    }
}

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.

 

Add a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.