Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force to write uppercase in searchview in android

I need to force user to write in uppercase letters in searchview v7 Do you know a way to do that? similar to that used in editText:

filter_text.setFilters(new InputFilter[]{new InputFilter.AllCaps()});
like image 790
Ali Noureddine Avatar asked Sep 11 '15 10:09

Ali Noureddine


2 Answers

In code you can do so by adding the following.

searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);

All of the other things you can add can be found here

like image 109
SARose Avatar answered Oct 08 '22 19:10

SARose


Edit:

Actually a better way is to do

searchView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

Alternatively, you can also set the android:inputType to textCapWords inside searchable.xml that you will create if you followed the official SearchView setup guide.

https://developer.android.com/training/search/setup.html

like image 44
Ali Kazi Avatar answered Oct 08 '22 19:10

Ali Kazi