我希望点击搜索后虚拟键盘消失。这是我到目前为止的代码:
query.EditorAction += (sender, e) => {
if (e.ActionId == ImeAction.Search)
{
HideKeyboard ();
pushSearch();
}
else
{
e.Handled = false;
}
};
private void HideKeyboard() {
InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(query.WindowToken, 0);
}
在XML中:
<EditText
android:id="@+id/query"
android:layout_width="fill_parent"
android:singleLine="true"
android:layout_height="wrap_content"
android:layout_weight="1"
android:imeOptions="actionSearch"
android:inputType="text"
android:hint="Zoek totem" />
如果我调试并在if中的pushSearch()上放置一个断点,它永远不会被调用。
任何人都知道我忘记了什么?
答案 0 :(得分:0)
试试这个:
private void HideKeyboard ()
{
View View = CurrentFocus;
if (View != null) {
InputMethodManager inputManager = (InputMethodManager)GetSystemService (Context.InputMethodService);
inputManager.HideSoftInputFromWindow (View.WindowToken, HideSoftInputFlags.None);
}
}
答案 1 :(得分:0)
试试这个,从currentfocus获取窗口的标记:
InputMethodManager inputManager = (InputMethodManager)this.GetSystemService (Context.InputMethodService);
inputManager.HideSoftInputFromWindow (this.CurrentFocus.WindowToken, HideSoftInputFlags.NotAlways);