OnKeyboardActionListener android 按键
我正在尝试实现一种方法来知道何时按下和释放软键盘上的按键。我已经使用 onKeyListener 来获取按键的向下和向上,但问题是它仅适用于硬键盘。我发现 OnKeyBoardActionListener 似乎具有此功能。我遇到的问题是我需要从我用于简单测试的编辑文本中获取KeyboardView。
public class testing extends Activity implements KeyboardView.OnKeyboardActionListener{
EditText testingBox;
TextView textbox;
KeyboardView keyView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textbox = (TextView)findViewById(R.id.TextView01);
testingBox = (EditText)findViewById(R.id.EditText01);
//keyView is null i need to get it somehow.
keyView.setOnKeyboardActionListener(this);
}
//methods for the OnKeyBoardActionListener
}
如果有人可以提供有关如何获取此 keyBoardView 或我可以捕获这些软键盘按下和释放的其他方式的任何建议,那就太好了。谢谢。
I'm trying to implement a way to know when there is a press and a release of a key on a soft keyboard. I have used the onKeyListener to get the down and the up of the key, but the problem with that is that it only works on a hard keyboard. I have found the OnKeyBoardActionListener which seems to have this functionality. The problem I am running into with this is that i need to get the KeyboardView from an edittext i am using for simple testing.
public class testing extends Activity implements KeyboardView.OnKeyboardActionListener{
EditText testingBox;
TextView textbox;
KeyboardView keyView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textbox = (TextView)findViewById(R.id.TextView01);
testingBox = (EditText)findViewById(R.id.EditText01);
//keyView is null i need to get it somehow.
keyView.setOnKeyboardActionListener(this);
}
//methods for the OnKeyBoardActionListener
}
if anyone could provide any advice on how i can get this keyBoardView or another way i can capture these soft keyboard presses and releases would be great. thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信捕获软键盘的准确按下和释放的唯一方法是从 IME 内部。您可以通过 TextWatcher 看到文本的变化。
我认为这部分是因为输入法可能没有按键上下机制。 IME 不一定需要看起来像标准的 qwerty 键盘。它可能类似于 Swype,你画一个图案,然后就会出现单词。
I believe the only way to capture the exact press and releases of a softkeyboard is from within the IME. You can see the text changing via a TextWatcher.
I think this is partially because an IME may not have key down and up mechanisms. An IME does not necessarily need to look like a standard qwerty keyboard. It might be something like Swype, where you draw a pattern and words come out.