Text-transform:uppercase equivalent in Android?

Android

Android Problem Overview


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

Android Solutions


Solution 1 - Android

Try this:

   <TextView 
        	android:textAllCaps="true"
    />

Solution 2 - Android

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) {
	}
};

Solution 3 - Android

For your EditText you can use InputFilter.AllCaps as filter

editText.setFilters(new InputFilter[]{new InputFilter.AllCaps()});

See: http://d.android.com/reference/android/text/InputFilter.AllCaps.html

Also you can specify your EditText via android:inputType:

<EditText
    ...
    android:inputType="textCapCharacters" />

Solution 4 - Android

use

android:textAllCaps="true" 

this will make your all Textview capital.

Solution 5 - Android

You could do it, only adding TYPE_TEXT_FLAG_CAP_CHARACTERS to InputType::

editText.setInputType(android.text.InputType.TYPE_CLASS_TEXT
                   + android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);

I hope be helped!

Solution 6 - Android

I found this at android developers guide:

<TextView 
...
android:capitalize="characters"
...
/>

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
QuestionJorenView Question on Stackoverflow
Solution 1 - AndroidTheLDView Answer on Stackoverflow
Solution 2 - Androidlander16View Answer on Stackoverflow
Solution 3 - AndroidsynergyView Answer on Stackoverflow
Solution 4 - AndroidDilipView Answer on Stackoverflow
Solution 5 - AndroidAlex PimentaView Answer on Stackoverflow
Solution 6 - AndroidJoseAntonioView Answer on Stackoverflow