问题
I don't manage to set the numeric input type to the 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 searchable configuration to the 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 is set correctly, but the line android:inputType="number" seems to have no effect, i.e. the numeric keypad doesn't appear.
Does anyone have a solution for this?
回答1:
Add this in your searchable.xml layout file:
android:numeric="decimal"
or If not useful then try,
android:inputType="phone"
And let me know what happen.
回答2:
This should work :
SearchView searchView = new SearchView(getContext());
searchView.setInputType(InputType.TYPE_CLASS_NUMBER);
回答3:
try this
android:inputType="phone"
来源:https://stackoverflow.com/questions/8293552/set-numeric-input-type-to-searchview-in-actionbar