OnKeyboardActionListener android 按键

发布于 2024-10-07 07:31:38 字数 809 浏览 3 评论 0原文

我正在尝试实现一种方法来知道何时按下和释放软键盘上的按键。我已经使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许你一世情深 2024-10-14 07:31:38

我相信捕获软键盘的准确按下和释放的唯一方法是从 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文