Set upper case for TextView
AndroidAndroid LayoutAndroid 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);