Set upper case for TextView

AndroidAndroid Layout

Android Problem Overview


I have TextView. I would like to show text in upper case mode. Is there attributed for upper case? Just I have text in strings.xml and I need use the line in several place as lower case and upper case.

Android Solutions


Solution 1 - Android

In the layout XML, you can set the android:textAllCaps attribute on your TextView:

<TextView android:textAllCaps="true"></TextView>

Solution 2 - Android

Use String class method while setting the text to TextView as

tv.setText(strings.toUpperCase());

Have a look at this post for detail discussion.

EDIT: This was answered way back before API 14. As other answer mentioned here, textView.isAllCaps = true and its java methods were introduced from TextView. Please use those.

Solution 3 - Android

use this for programatically like textView.setAllCaps(false) for as it is and textView.setAllCaps(true)for Uppercase android:textAllCaps="true" for XML Layout

Solution 4 - Android

Kotlin:

textView.isAllCaps = true

Solution 5 - Android

For an XML approach, you don't want to use android:capitalize because this is intended for use during text input. Instead, use [textAllCaps][1]. If your strings are declared as lower case, then it is quite simple to toggle between upper and lower case on a per-TextView basis.

[1]: http://developer.android.com/reference/android/widget/TextView.html#attr_android:textAllCaps "textAllCaps"

Solution 6 - Android

use it

<TextView android:textAllCaps="true"></TextView>

Solution 7 - Android

I believe there is no such attribute, but you can use

textView.setText(text.toUpperCase());

also found this, never tested by myself though

android:capitalize="characters"

Solution 8 - Android

Try this.

Upper Case

textView.setText(getResources().getString(R.string.app_name).toUpperCase());

Lower Case

textView.setText(getResources().getString(R.string.app_name).toLowerCase());

Solution 9 - Android

Set android:textAllCaps="true" in layout file.

Edit : If you are using kotlin use .capliatlized() method https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/capitalize.html

Solution 10 - Android

You could create a custom view derived from TextView and override the setText method to capitalize.

Solution 11 - Android

You can do that easily in android xml file. you should add this line to TextView.

 <TextView 
      android:textAllCaps="true"/>

if you want to do that in code, you can do like this :

        textView.setText(strings.toUpperCase());

Solution 12 - Android

Get a reference for your TextView and call this method on the object

    textView.setAllCaps(true);

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
QuestionTimView Question on Stackoverflow
Solution 1 - AndroidBen HutchisonView Answer on Stackoverflow
Solution 2 - AndroidAdil SoomroView Answer on Stackoverflow
Solution 3 - AndroidRajeshView Answer on Stackoverflow
Solution 4 - AndroidMetuView Answer on Stackoverflow
Solution 5 - AndroidcalsignView Answer on Stackoverflow
Solution 6 - AndroidyousefView Answer on Stackoverflow
Solution 7 - AndroidslezadavView Answer on Stackoverflow
Solution 8 - AndroidChiragView Answer on Stackoverflow
Solution 9 - AndroidGevaria PurvaView Answer on Stackoverflow
Solution 10 - AndroidSameerView Answer on Stackoverflow
Solution 11 - AndroidWhitebirdView Answer on Stackoverflow
Solution 12 - AndroidهيثمView Answer on Stackoverflow