Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable small character EditText InputType

Is there any way to achieve like below image? I have an EditText and i want InputType is always Caps. I tried using this

android:inputType="textCapCharacters"

its working fine but when i press top Arrow icon from softkeyboard(shown in below image) and start typing text will be in small character. Is there any way to Disable the top arrow key?

Thanks

enter image description here

like image 811
Geeta Gupta Avatar asked Dec 14 '25 17:12

Geeta Gupta


2 Answers

You can do it through code as follow:

Applying UpperCase as the only filter to an EditText

Here we are setting the UpperCase filter as the only filter of the EditText. Notice that doing it this way you are removing all the previously added filters(maxLength, maxLines,etc).

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

Adding UpperCase to the existing filters of an EditText

To keep the already applied filters of the EditText (let's say maxLines, maxLength, etc) you need to retrieve the applied filters, add the UpperCase filter to those filters, and set them back to the EditText. Here is an example how:

InputFilter[] editFilters = editText.getFilters();
InputFilter[] newFilters = new InputFilter[editFilters.length + 1];
System.arraycopy(editFilters, 0, newFilters, 0, editFilters.length);
newFilters[editFilters.length] = new InputFilter.AllCaps();  
editText.setFilters(newFilters);
like image 75
Ricardo Avatar answered Dec 16 '25 07:12

Ricardo


It works for me, Try this

edittext.setInputType(InputType.TYPE_CLASS_TEXT);
edittext.setFilters(new InputFilter[]{new InputFilter.AllCaps()});
like image 31
Shankar Avatar answered Dec 16 '25 07:12

Shankar