android键盘的Done按钮
16lz
2021-01-24
在EditText中,可以使用setImeOptions()方法来来开启软键盘的"Done"按钮。 示例代码如下: editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
EditorInfo.IME_ACTION_DONE 可以和其他的标志一起组合使用来设置软键盘,比如: editText.setImeOptions( EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_DONE ); 注意1 : EditorInfo.IME_ACTION_DON E 只有对 android:singleLine="true" 的EditText有效。至少对HTC_A9191是这样的。 注意2:对于 EditorInfo.IME_ACTION_DON E ,有些输入法并不支持它,比如搜狐拼音输入法。
按下"Done"按钮的默认行为是关闭软键盘,但是我们可以通过EditText的setOnEditorActionListener()方法来设置OnEditorActionListener以便添加自己的行为.
捕获Android文本输入框的软键盘完成(Done)按键消息:editText.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { InputMethodManager imm = (InputMethodManager)v.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); doSomething(); return true; } return false; } });
EditorInfo.IME_ACTION_DONE 可以和其他的标志一起组合使用来设置软键盘,比如: editText.setImeOptions( EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_DONE ); 注意1 : EditorInfo.IME_ACTION_DON E 只有对 android:singleLine="true" 的EditText有效。至少对HTC_A9191是这样的。 注意2:对于 EditorInfo.IME_ACTION_DON E ,有些输入法并不支持它,比如搜狐拼音输入法。
更多相关文章
- [置顶] Android(安卓)按钮点击两次触发不同的事件
- android学习笔记一
- Android(安卓)软键盘顶起布局相关
- DataBinding 填坑总结
- Android(安卓)AlertDialog对话框详解及实例
- AndroidGUI14:各种Dialog常用技巧
- Android(安卓)系统原生dialog使用
- Android键盘的显示与隐藏
- Android(安卓)各控件的使用 - 按钮(Button)