android自定义软键盘拦截ime_action

android custom soft keyboard intercepting ime_action

我目前正在 android 中制作自己的软键盘,但很难选择 ime 操作 -(IME_ACTION_SEARCHIME_ACTION_DONE 等)。

例如,如果用户输入 google 搜索,则操作按钮应为搜索按钮,如果是短信,则为换行符。我如何区分它们?

我试过在 中寻找它,但没有成功。

onCreateInputView(){}

感谢任何帮助。

您可以拨打getCurrentInputEditorInfo on your InputMethodService. Then you can inspect the EditorInfo's imeOptions property.

int imeOptions = mInputMethodService.getCurrentInputEditorInfo().imeOptions;
switch (imeOptions&EditorInfo.IME_MASK_ACTION) {
            case EditorInfo.IME_ACTION_NONE:
                // None
            case EditorInfo.IME_ACTION_GO:
                // Go
            case EditorInfo.IME_ACTION_SEARCH:
                // Serach
            case EditorInfo.IME_ACTION_SEND:
                // Send
            case EditorInfo.IME_ACTION_NEXT:
                // Next
            case EditorInfo.IME_ACTION_DONE:
                // Done
        }