好吧,这个问题已经被问过很多次了,我已经浏览了很多关于它的主题,但我无法让它工作。
我的 searchView
不在 actionBar 上,所以我不能使用 collapseActionView()
我试过了
searchView.clearFocus();//this closes the keyboard but does not remove focus
getActivity().getCurrentFocus().clearFocus(); //basically the same as above
searchView.setQuery("", false); //this clears the query and drops the keyboard
searchView.setIconified(true); // but the search retains focus and keyboard pops up again
无论我尝试什么,我都无法在选择 searchView
后将其移走
最佳答案
为了在执行查询后从我的 searchView 中清除焦点,我首先必须添加
android:focusable="true"
android:focusableInTouchMode="true"
到 Activity 的父级布局。然后在 Activity 中
LinearLayout myLayout = (LinearLayout) activity.findViewById(R.id.my_layout);
myLayout.requestFocus();
这会将焦点从 searchView 上移开。我需要的所有信息都在这里 How to remove focus without setting focus to another control?
关于Android searchView 不在 actionBar 中移除焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32563377/