Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text-transform:uppercase equivalent in Android?

Tags:

android

Does this exist? I need to make a TextView which is always uppercase.

like image 217
Joren Avatar asked Jul 20 '10 01:07

Joren


2 Answers

Try this:

   <TextView              android:textAllCaps="true"     /> 
like image 180
TheLD Avatar answered Sep 24 '22 19:09

TheLD


I don't see anything like this in the TextView attributes. However, you could just make the text uppercase before setting it:

textView.setText(text.toUpperCase()); 

If the TextView is an EditText and you want whatever the user types to be uppercase, you could implement a TextWatcher and use the EditText addTextChangedListener to add it, and on the onTextChange method take the user input and replace it with the same text in uppercase.

editText.addTextChangedListener(upperCaseTextWatcher);  final TextWatcher upperCaseTextWatcher = new TextWatcher() {      public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {     }      public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {         editText.setText(editText.getText().toString().toUpperCase());         editText.setSelection(editText.getText().toString().length());     }      public void afterTextChanged(Editable editable) {     } }; 
like image 24
lander16 Avatar answered Sep 21 '22 19:09

lander16