改变"完成"在我的软键盘上标记为"搜索,下一步"根据EditText ime选项

时间:2015-03-20 08:36:46

标签: android ime soft-keyboard imeoptions

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

2 个答案:

答案 0 :(得分:0)

检查此链接。有不同的行动。选择你需要的那个。

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

答案 1 :(得分:0)

最后我发现了它。创建一个扩展Keyboard的类,并添加以下方法并从InputMethodService类中调用它。

@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;
    }
}