Allow uppercase letters only in Edittext

Asked

Viewed 3,003 times

3

I know I can make the Edittext screen is always rotated, now I want to know if there is a way to only allow uppercase letters at the moment the user is typing something.

4 answers

2


The android has a InputFilter for this, as you can see in the official documentation. With this simply set the filter through the method setFilters() of your EditText.

Ex:

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

2

If you put android:inputType="textCapCharacters" in XML it will prioritize the uppercase letter, but the user will be able to change depending on the device, so I suggest that you contort when you take the input data as follows:

String algumaString = seuEdittext.getText().toString().toUpperCase();

0

Edittext has a property called setInputType that takes an int value from the Inputtype class where Voce can programmatically change the user input while the user is typing, however I believe it is not possible to limit only characters because depending on the keyboard of the device it is possible for the user to click on the symbol button and select a number for example.

-2

In Edittext there is a property called Charcase, for Maiuscula put in Uppercase and for Lowercase Lowercase. I hope to have helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.