Android:HTC Desire 上的软键盘控制

发布于 2024-09-26 06:43:36 字数 183 浏览 2 评论 0原文

我想要一个带有“执行”或“完成”按钮的数字键盘,可以关闭并执行计算类。感谢来自 Commonware 的关于从哪里开始的提示,我在模拟器上完美地工作了。然后我把它加载到我的 HTC 愿望上进行测试,但它根本不起作用。我确信这一定是因为 HTC sense 有自己的 ime,但一定有办法让这个功能在 HTC 手机上运行吗?还有其他人设法解决这个问题吗?

I wanted a numeric keypad that had a go or done button that closed and executed a calculation class. Thanks to a tip from commonware on where to start I got this working beautifully on the emulator. Then I came to load it on to my HTC desire for testing and it doesn't work at all. I'm sure it must be because of HTC sense having it's own ime but there must surely be a way to make this work on HTC phones? Anyone else managed to get around this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

≈。彩虹 2024-10-03 06:43:36

我可以复制您在 HTC Incredible 上看到的内容。

并非所有软键盘都支持 IME 操作按钮。有些(例如 Graffiti 软“键盘”)可能根本没有按钮,更不用说 IME 操作按钮了。甚至兼容性定义文档也没有提到为附带的键盘需要这样的操作按钮设备。

因此,您不应依赖 IME 操作按钮。如果存在,用户就可以使用它。然而,无论你的目标是什么,总是有一些其他的方法来实现。

I can replicate what I think you are seeing on the HTC Incredible.

Not all soft keyboards will support the IME action button. Some, like the Graffiti soft "keyboard", may have no buttons at all, let alone an IME action button. Even the Compatibility Definition Document says nothing about requiring such an action button for the keyboards supplied with a device.

Hence, you should not rely on the IME action button. If it is there, users can use it. However, always have some other means of accomplishing whatever your goal is.

森末i 2024-10-03 06:43:36

我正在使用 onEditorActionListener 检测是否按下了 DONE / GO / RETURN 按钮,但检查 IME 选项和 KeyEvents 以涵盖 HTC 键盘以及任何接受 IME 选项的键盘。

(此代码适用于 HTC Incredible 键盘以及任何具有 IME 选项的键盘)

EditText.setOnEditorActionListener(new TextView.OnEditorActionListener(){
    public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event){
        if(actionId == EditorInfo.IME_ACTION_DONE 
            || actionId == EditorInfo.IME_NULL
            || event.getKeyCode() == KeyEvent.KEYCODE_ENTER){

            //Do something in here
            return true;
        } else {
            return false;
        }
    }
});

I am detecting whether the DONE / GO / RETURN button has been pressed using an onEditorActionListener, but checking for IME options and KeyEvents to cover HTC keyboards as well as any keyboards that accept IME options.

(This code works for HTC Incredible keyboards as well any keyboard that has IME options)

EditText.setOnEditorActionListener(new TextView.OnEditorActionListener(){
    public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event){
        if(actionId == EditorInfo.IME_ACTION_DONE 
            || actionId == EditorInfo.IME_NULL
            || event.getKeyCode() == KeyEvent.KEYCODE_ENTER){

            //Do something in here
            return true;
        } else {
            return false;
        }
    }
});
骄傲 2024-10-03 06:43:36

我使用带有 inputType="number" 的 EditText 并通过修改 Asha 的解决方案解决了问题:

private TextView.OnEditorActionListener numberEnterListener = new TextView.OnEditorActionListener(){
        public boolean onEditorAction(TextView tv, int actionId, KeyEvent event){
            if(actionId == EditorInfo.IME_ACTION_DONE 
                || actionId == EditorInfo.IME_NULL
                || event.getKeyCode() == KeyEvent.KEYCODE_ENTER){

                tv.clearFocus();

                //Stupid keyboard needs to be closed as well
                InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(tv.getWindowToken(), 0);

                return true;
            } else {
                return false;
            }
        }
    };

焦点被移除以停止显示数字键盘。需要 IMM 是因为即使在清除焦点后软键盘仍然存在。

I was using an EditText with inputType="number" and solved the problem by modifying Asha's solution:

private TextView.OnEditorActionListener numberEnterListener = new TextView.OnEditorActionListener(){
        public boolean onEditorAction(TextView tv, int actionId, KeyEvent event){
            if(actionId == EditorInfo.IME_ACTION_DONE 
                || actionId == EditorInfo.IME_NULL
                || event.getKeyCode() == KeyEvent.KEYCODE_ENTER){

                tv.clearFocus();

                //Stupid keyboard needs to be closed as well
                InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(tv.getWindowToken(), 0);

                return true;
            } else {
                return false;
            }
        }
    };

The focus was removed in order to stop showing the number pad. The imm was required because a soft keyboard was still present even after clearing focus.

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