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.
13 Answers
In the layout XML, you can set the android:textAllCaps
attribute on your TextView
:
<TextView android:textAllCaps="true"></TextView>

- 4,823
- 4
- 26
- 25
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.

- 37,609
- 9
- 103
- 153
use this for programatically like textView.setAllCaps(false)
for as it is and textView.setAllCaps(true)
for Uppercase
android:textAllCaps="true"
for XML Layout

- 2,618
- 19
- 25
-
2but this works from API 14 and above.. does not work for API level below 14, any solution ? – Rizwan Sohaib Mar 03 '15 at 07:27
Kotlin:
textView.isAllCaps = true

- 1,033
- 1
- 13
- 20
-
Since `TextView` doesn't have a getter for all caps, Kotlin doesn't make a property available to you, you still need to call `setAllCaps(true)`. – tinsukE Jul 10 '18 at 12:29
-
Weird thing to observe and only because of that I am looking over internet. I am able to use `TextView#isAllCaps` but it's giving lint error on QA's system and making him to change to `TextView#setAllCaps()`. But giving me lint warning for that – Jimit Patel Mar 19 '19 at 13:26
-
1Ok got it. API version for `maxSdkVersion` less than 28 will give the lint error for `TextView#isAllCaps`. 28 and above will work smooethly – Jimit Patel Mar 19 '19 at 15:32
For an XML approach, you don't want to use android:capitalize
because this is intended for use during text input. Instead, use textAllCaps. 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.

- 341
- 3
- 12
-
I like this approach, but just as a warning this is only available from API 14 onwards. – Kevin Coppock Aug 28 '12 at 13:10
-
@kcoppock Ah, I was unaware of this. Hopefully it's useful to someone, though. – calsign Aug 28 '12 at 13:16
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"

- 6,104
- 7
- 40
- 61
Try this.
Upper Case
textView.setText(getResources().getString(R.string.app_name).toUpperCase());
Lower Case
textView.setText(getResources().getString(R.string.app_name).toLowerCase());

- 56,621
- 29
- 151
- 198
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

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

- 4,379
- 1
- 23
- 23
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());

- 218
- 1
- 11
Get a reference for your TextView and call this method on the object
textView.setAllCaps(true);

- 791
- 8
- 11
Try this,
Java
textView.setAllCaps(true)
Kotlin
textView.isAllCaps = true

- 89
- 1
- 2