我试图在gridview中单击项目后关闭我的自定义键盘。我正在BaseAdapter类中尝试这样做。上下文来自InputMethodService。

到目前为止,我已经在下面尝试过:

FrameLayout scroll = (FrameLayout)inflater.inflate(R.layout.keyboard, null);
 InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(scroll.getWindowToken(), 0);


--

imm.toggleSoftInput(0,InputMethodManager.HIDE_IMPLICIT_ONLY);


--

 scroll.setVisibility(View.INVISIBLE);

最佳答案

如果您有自己的自定义键盘并且扩展了InputMethodService,则只需致电

requestHideSelf(0)


从服务范围内强制关闭键盘或

requestHideSelf(InputMethodManager.HIDE_IMPLICIT_ONLY);


仅在用户未明确要求显示键盘时才关闭键盘。

文献资料


InputMethodService#void requestHideSelf (int flags)

10-08 06:19
查看更多