禁止在 EditText 焦点上显示软键盘
我试图定义一组按钮,允许用户将数据输入到 EditText 框中。我想要 EditText 框的所有默认功能,除了软键盘的弹出。唯一允许输入到 EditText 框中的数据应该是我定义的按钮中的数据。我试图通过捕获触摸事件并返回 true 来抑制软键盘。 (根据在此线程上找到的对话)
private OnTouchListener txtTouchListener = new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
//Return true to suppress the passing of the event on to the OS
return true;
}
};
问题在于然后,此方法会阻止长按事件的触发。为了解决这个问题,我可以返回 false,然后处理长按事件。然而,这会使短按一下调出软键盘。此外,长按时不仅软键盘会被抑制,上下文菜单也会被抑制。我正在寻找一种方法来阻止键盘在短(或长)单击时出现,但保留所有其他功能(短单击时更新光标位置,长单击时显示 EditText 上下文菜单等)
对此有任何想法非常感谢!
I am trying to define a set of buttons that allow the user to enter data into an EditText box. I want all the default functionality of an EditText box except for the pop up of the soft keyboard. the only data to be allowed to enter into the EditText box should be the data from the buttons I have defined. I am trying to suppress the soft keyboard by catching the touch event and returning true. (per the conversation found on this thread)
private OnTouchListener txtTouchListener = new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
//Return true to suppress the passing of the event on to the OS
return true;
}
};
The problem is that this method then blocks the long click event from firing. To solve this I can return false and then handle the long click event. However, this then makes the short click bring up the soft keyboard. Also, upon long click not only is the soft keyboard suppressed, but so is the context menu. I am looking for a way to stop the keyboard from appearing on a short (or long) click but keep all other functionality (updating the cursor position on short click, on long click show the EditText context menu, etc.)
Any ideas on this is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此线程建议:
不过我自己没试过。
This thread suggests:
Not tried it myself though.