Shankar Kumar
Shankar Kumar

Reputation: 1772

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

Upvotes: 3

Views: 966

Answers (5)

Ricardo
Ricardo

Reputation: 9676

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

Upvotes: 7

Shankar
Shankar

Reputation: 86

It works for me, Try this

edittext.setInputType(InputType.TYPE_CLASS_TEXT);
edittext.setFilters(new InputFilter[]{new InputFilter.AllCaps()});

Upvotes: 1

UltimateDevil
UltimateDevil

Reputation: 2847

Yes you can set programmatically. Android has built-in IntentFilter for this.

you can achieve this by using following code-:

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

But, there is an issue setFilters will reset all other attributes which were set via XML (like maxLines, inputType and other)

So, you need to set Filter like this,

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();  
//you can use another filter like for maxLength you can use
// newFilters[editFilters.length] = new InputFilter.LengthFilter(10);
<EditText>.setFilters(newFilters);

See here for information

This will work for you.

Upvotes: 0

user6672223
user6672223

Reputation:

YES you can do something like that

you can check for every letter typed by the user if it small letter convert it to its upper one

For Example:-

if the user typed e replace it with E

Upvotes: 0

Khalid Ali
Khalid Ali

Reputation: 373

You can control to respond directly to keyboard input for user actions. Check this link

Upvotes: 0

Related Questions