如何防止软件键盘弹出?
我的应用程序中有自己的键盘,因此我想始终隐藏软件键盘(在特定活动和对话框中)。 我尝试了两个选项:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
此代码阻止键盘在开始时弹出,但是当我单击文本框时,键盘仍然弹出。
InputMethodManager imm = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
这段代码隐藏了键盘,但并不能阻止键盘弹出。
请帮忙!
I have my own keypad in my application so I want to hide the software keyboard all the time(in specific activities & dialogs).
I experimented with two options:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
This code prevent the keyboard from popping up at the beginning, but when I click on the textbox the keyboard still pops.
InputMethodManager imm = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
This code hide the keyboard, but it doesn't prevent the keyboard from popping up.
PLEASE HELP!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于想通了!
我用于
想要抑制键盘的活动(您可以将其放在所有其他活动继承的常规活动中)
但这不会阻止当您单击 EditText 文本框时弹出键盘。我所做的是消耗文本框的 onTouch 事件:
Finally figured out!
I used
for the activities where I want to suppress the keyboard(you can put it in a general activity where all other activities inherit from)
But this won't prevent the keyboard from popping up when you click on the EditText textbox. What I did is I consumed the onTouch event for the text box: