我在布局中添加了一个SearchView(不是在操作栏中),但是我无法使用通常的方法来隐藏键盘:
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);
}
}
}
SearchView保持其焦点状态。在旧设备上使用此方法会显示键盘被解除,然后重新显示。
我认为问题在于SearchView实际上是一组维护其内部状态的视图层次结构。
我该如何解除键盘并取消SearchView的焦点?