如何根据文本字段更改 android 自定义键盘的操作键?

How to change action key of android custom keyboard according to the text field?

我正在开发 android 键盘。我正在尝试根据用户选择的文本字段使用此方法更改我的自定义键盘操作键。但是这种方法不起作用。有没有其他方法可以更改操作键?

public class MyKeyboard extends InputMethodService implements
        OnKeyboardActionListener {

    @Override
    public void onStartInputView(EditorInfo info, boolean restarting) {
        super.onStartInputView(info, restarting);

        if(info.actionId == EditorInfo.IME_ACTION_DONE){
            //Action Done
        }else if(info.actionId == EditorInfo.IME_ACTION_SEARCH){
            //Action Search
        }else if(info.actionId == EditorInfo.IME_ACTION_UNSPECIFIED){
            //Action Unspecified
        }

        //more code here
    }

}

我在键盘中使用了这个 class。

    public class LatinKeyboard extends Keyboard {
         /**
         * This looks at the ime options given by the current editor, to set the
         * appropriate label on the keyboard's enter key (if it has one).
         */
        void setImeOptions(Resources res, int options) {

            switch (options&(EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
                case EditorInfo.IME_ACTION_GO:
                   //Action GO
                   break;
                case EditorInfo.IME_ACTION_NEXT:
                   //Action Next
                   break;
                case EditorInfo.IME_ACTION_SEARCH:
                    //Action Search
                    break;
                case EditorInfo.IME_ACTION_SEND:
                    //Action SEND
                    break;
                default:
                    //Action Default
                    break;
            }
        }
}

这里的选项是来自EditorInfo的imeOptions,我在onStartInput中调用了这个方法。