Joren Joren - 6 months ago 25
Android Question

Text-transform:uppercase equivalent in Android?

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

Answer

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, an 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) {
}

};