set numeric input type to SearchView in ActionBar

﹥>﹥吖頭↗ 提交于 2019-12-23 12:33:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!