我正在为 Android 开发一个软键盘,我希望根据 EditText ime 选项将“DONE”键 (KEYCODE_DONE) 更改为“search, next”。我怎样才能做到这一点?
问问题
962 次
2 回答
1
最后我找到了。创建一个扩展键盘的类并添加以下方法并从 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;
}
}
于 2015-03-20T10:26:10.920 回答
0
检查此链接。有不同的动作。选择您需要的那个。
http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions
于 2015-03-20T08:55:13.213 回答