Android的:如何编程一个无焦点搜索查看 [英] Android: How to unfocus a SearchView programmatically
问题描述
我有一个搜索查看我的布局(而不是在操作栏),我无法用通常的方法来取消键盘:
I have a SearchView in my layout (not in the action bar) and I'm unable to dismiss the keyboard using the usual method:
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager)activity
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null && activity != null) {
View currentFocus = activity.getCurrentFocus();
if (currentFocus != null) {
imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
}
}
}
该搜索查看其保持对焦状态。旧设备上使用此方法显示被解雇键盘,然后重新显示。
The SearchView maintains its focus state. Using this method on older devices shows the keyboard being dismissed then redisplaying.
我相信这个问题是一个事实,即搜索查看实际上是在内部保持自己的状态视图的层次结构。
I believe the issue is with the fact that a SearchView is actually a hierarchy of Views that maintain their own state internally.
我怎么不显示键盘并在无焦点搜索查看?
How do I dismiss the keyboard and unfocus the SearchView?
推荐答案
这听起来像什么可能发生的事情是,你unfocusing的搜索查看,然后它说:哦,等等,我还是有重点,我需要的键盘 。是否 activity.getCurrentFocus()。clearFocus()
清除重点是什么?
It sounds like what might be happening is that you're unfocusing the SearchView and then it's saying "oh wait, I still have focus, I need the keyboard". Does activity.getCurrentFocus().clearFocus()
clear out the focus?
这篇关于Android的:如何编程一个无焦点搜索查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!