Android处理自定义键盘上的“搜索"按钮 [英] Android handle 'search' button press on custom keyboard

查看:88
本文介绍了Android处理自定义键盘上的“搜索"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发自己的自定义键盘.

I'am developing my own custom keyboard.

如果我们的键盘使用 IME_ACTION_SEARCH 参数打开的话,如何处理搜索"按钮的按下操作?

How to handle 'search' button press in case if our keyboard opened with IME_ACTION_SEARCH parameter?

我有以下代码,但不幸的是,在搜索情况下它不起作用.在正常情况下,使用完成"按钮可以很好地工作.

I have following code, but unfortunately in search case it's not working. In regular situation with Done button it working good.

        final int options = this.getCurrentInputEditorInfo().imeOptions;
        final int actionId = options & EditorInfo.IME_MASK_ACTION;

        switch (actionId) {
            case EditorInfo.IME_ACTION_SEARCH:
                ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SEARCH));
                break;
            default:
                ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
        }

谢谢

推荐答案

我找到了解决方案:

endDefaultEditorAction(true);

这是 InputMethodService

完整代码是:

    case Keyboard.KEYCODE_DONE:
        final int options = this.getCurrentInputEditorInfo().imeOptions;
        final int actionId = options & EditorInfo.IME_MASK_ACTION;

        switch (actionId) {
            case EditorInfo.IME_ACTION_SEARCH:
                sendDefaultEditorAction(true);
                break;
            case EditorInfo.IME_ACTION_GO:
                sendDefaultEditorAction(true);
                break;
            case EditorInfo.IME_ACTION_SEND:
                sendDefaultEditorAction(true);
                break;
            default:
                ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
        }

        break;

这篇关于Android处理自定义键盘上的“搜索"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆