根据 EditText imeoptions 将我的软键盘上的 "Done" 标签更改为 "Search,Next"

Change "Done" label on my softkeyboard to "Search,Next" according to EditText ime options

我正在为 Android 开发软键盘,我希望根据 EditText 输入法选项将 "DONE" 键 (KEYCODE_DONE) 更改为 "search, next"。我怎样才能做到这一点?

检查此 link。有不同的动作。 select 你需要的那个。

http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions

终于找到了。创建一个扩展 Keyboard 的 class 并添加以下方法并从 InputMethodService class.

调用它
@Override
protected Key createKeyFromXml(Resources res, Row parent, int x, int y, XmlResourceParser parser) {
    Key key = new Key(res, parent, x, y, parser);
    if (key.codes[0] == -4) {
        mEnterKey = key;
    }
    return key;
}

private Key mEnterKey;
void setImeOptions(Resources res, int options) {
    if (mEnterKey == null) {
        return;
    }

    switch (options & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
        case EditorInfo.IME_ACTION_GO:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.label = "Go";
            break;
        case EditorInfo.IME_ACTION_NEXT:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.label = "Next";
            break;
        case EditorInfo.IME_ACTION_SEARCH:
            mEnterKey.icon = null;
            mEnterKey.iconPreview = null;
            mEnterKey.label = "Search";
            break;
        case EditorInfo.IME_ACTION_SEND:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.label = "Send";
            break;
        default:
            mEnterKey.icon = null;
            mEnterKey.iconPreview = null;
            mEnterKey.label = "Return";
            break;
    }
}