Set numeric input type in SearchView to ActionBar

I am unable to set the numeric input type in SearchView in my ActionBar. I have the following searchable.xml file in my res / xml folder:

<searchable xmlns:android="http://schemas.android.com/apk/res/android" android:inputType="number" android:label="@string/app_name" android:hint="@string/search_hint"> </searchable> 

And I set the search configuration in SearchView as follows:

  // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); 

The search_hint function is set correctly, but the android line : inputType = "number" seems to have no effect, i.e. the numeric keypad is not displayed.

Does anyone have a solution for this?

+4
source share
3 answers

Add this to the searchable.xml layout file:

 android:numeric="decimal" 

or If not useful, try

android:inputType="phone"

And let me know what will happen.

+2
source

This should work:

 SearchView searchView = new SearchView(getContext()); searchView.setInputType(InputType.TYPE_CLASS_NUMBER); 
+1
source

try it

 android:inputType="phone" 
0
source

Source: https://habr.com/ru/post/907973/


All Articles