Cancel on SearchView causing the soft keyboard to appear
Even if my SearchView is not in focus (ie. the user has already pressed the "Search" button earlier to submit their query), when I press the cancel (the X) button on my Android SearchView, the soft keyboard comes back up into view.
My thinking is that if the user doesn't already have the keyboard on the screen, then they just want to clear the filter/search box. If they want to clear the filter and type something different they can tap it again.
However, if they are typing into the box and make a mistake I would expect the keyboard to remain in view (because the search view already has focus).
So in a nutshell I want:
I know I can use the setOnCloseListener()
event to hook into when the clear/close button is pressed, but I don't know how to stop it from showing the soft keyboard as mentioned in point #2.
EDIT:
Maybe there is a way I can have the search view "lose focus"? How do I achieve this result? Thanks.
You can lose focus by doing the following:
searchView.clearFocus();
You can also force hiding the keyboard on any event you want with the inputManager
.
For example:
InputMethodManager inputManager = (InputMethodManager) this
.getSystemService(Context.INPUT_METHOD_SERVICE);
//check if no view has focus:
View v=this.getCurrentFocus();
if(v==null)
return;
inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
链接地址: http://www.djcxy.com/p/92962.html
上一篇: 无法使用搜索视图来过滤列表视图
下一篇: 取消SearchView会导致软键盘出现