无法隐藏搜索查看iconfiedbydefault的虚拟键盘(假)键盘、iconfiedbydefault

2023-09-08 09:09:25 作者:逛妓找名婊。

我有设定为扩张在默认情况下使用默认的搜索查询,但我不希望低于codeI虚拟keyboard.In搜索视图试图在 onCreateOptionsMenu ,但仍隐藏键盘键盘是可见的。

I have a search view which is set as expanded by default with default search query but i don't want the virtual keyboard.In below code i tried to hide keyboard in onCreateOptionsMenu but still keyboard is visible.

imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    MenuItem item = menu.findItem(R.id.menu_search);
    item.expandActionView();
    mSearchView = (SearchView) item.getActionView();
    mSearchView.setIconifiedByDefault(false);
    mSearchView.setQuery(query, true);
    imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);

我使用的福尔​​摩斯搜索视图控件。任何建议,隐藏虚拟keyboard.What我做错了什么?

I am using sherlock search view widget. any suggestion to hide the virtual keyboard.What i am doing wrong?

推荐答案

由Parnit的回答启发,我已经找到一个更好的方法,该方法也适用,更美观:

Inspired by Parnit's answer, I've found a better method, which also works and is more beautiful:

mSearchView.clearFocus();
 
精彩推荐
图片推荐