android:imeOptions
改变输入法右下角完成按钮的文字
UE提出想改输入键盘输入法右下角的enter button的文字,但是经过一番探索发现自定义几乎是不可能的。
我们只能通过设定TextView 的 android:imeOptions ,在几个行为模式间切换
actionGo(开始)
actionSearch(搜索)
actionSend(发送)
actionNext(下一个)
actionDone(完成)
actionPrevious(前一个)
actionUnspecified 未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.
actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE
android:imeActionLabel
这个不是用来给我们自定义右下角这个enter button的文字用的,用它设置的文字的用途是:
The full label is only displayed when the IME has a large amount of space for it (such as when the standard keyboard is in fullscreen mode).只有在IME有大量空间时(例如标准键盘处于全屏模式时),才会显示完整的标签。链接: https://www.jianshu.com/p/b39dec5d53fe
imeActionLabel不是用于自定义按钮文字的。
例如你设置android:imeActionLabel="添加",android:imeOptions="actionDone",则有些软键盘的Enter键会显示“添加”而不是“完成”或其它。但是这种设置不是在所有手机上都有效果,一般手机自带的软键盘有效果的可能性很大,第三方软键盘有效果的可能性很小。而且即使显示了“添加”也是有问题的。总之,不要试着用imeActionLabel自定义文字
如果你用了android:imeOptions但是没有效果,则应该加上android:singleLine="true"。
当然,无论是imeOptions还是imeActionLabel等,都可以通过java代码实现,不一定要在布局文件中设置。
第二步:在代码中监听按键
以监听actionDone为例:
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
//TODO:你自己的业务逻辑
return true;
}
return false;
}
});
...