android:imeOptions="actionDone"
2013-08-07 14:42
429 查看
把EditText的Ime Options属性设置成不同的值,Enter键上可以显示不同的文字或图案
actionNone : 回车键,按下后光标到下一行
actionSend : Send
actionNext : Next
![](http://images.cnitblog.com/blog/363274/201309/05150622-410008ad4fda47db8808c5ef5574b9b7.jpg)
actionDone : Done,隐藏软键盘,即使不是最后一个文本输入框
设置android:imeOptions="actionDone" 可能监听不到键盘的是事件KeyEvent.KEYCODE_DPAD_CENTER 或者KeyEvent.KEYCODE_ENTER事件
可以 实现 setOnEditorActionListener 的onEditorAction
在EditorInfo的说明中能够找到。列举如下:
软键盘的Enter键默认显示的是“完成”文本,我们知道按Enter建表示前置工作已经准备完毕了,要去什么什么啦。比如,在一个搜索中,我们输入要搜索的文本,然后按Enter表示要去搜索了,但是默认的Enter键显示的是“完成”文本,看着不太合适,不符合搜索的语义,如果能显示“搜索”两个字或者显示一个表示搜索的图标多好。事实证明我们的想法是合理的,Android也为我们提供的这样的功能。通过设置android:imeOptions来改变默认的“完成”文本。这里举几个常用的常量值:
actionUnspecified 未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.效果:
![](http://dl.iteye.com/upload/attachment/355737/bd9d7b7c-2a93-37b3-afd9-cda2f3593058.png)
actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE 效果:
![](http://dl.iteye.com/upload/attachment/355737/bd9d7b7c-2a93-37b3-afd9-cda2f3593058.png)
actionGo 去往,对应常量EditorInfo.IME_ACTION_GO 效果:
![](http://dl.iteye.com/upload/attachment/355757/a8db4447-ec91-39aa-a546-c117db16cf55.png)
actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH 效果:
![](http://dl.iteye.com/upload/attachment/355769/c35d6b78-d5b9-314a-9698-144bc12d0af3.png)
actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND 效果:
![](http://dl.iteye.com/upload/attachment/355788/c168252f-bb3d-3831-8e3c-8bced16b12a1.png)
actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT 效果:
![](http://dl.iteye.com/upload/attachment/355798/aa6bd8b1-8ab3-38d9-b162-01ce10f4f998.png)
actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE 效果:
![](http://dl.iteye.com/upload/attachment/355804/79979746-7373-3377-bb7e-3dd4bdede464.png)
private TextView.OnEditorActionListener mWriteListener =
new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
// If the action is a key-up event on the return key, send the message
if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_UP) {
String message = view.getText().toString();
sendMessage(message);
}
if(D) Log.i(TAG, "END onEditorAction");
return true;
}
};
public static final int KEYCODE_SHIFT_RIGHT = 60;
public static final int KEYCODE_TAB = 61;
public static final int KEYCODE_SPACE = 62;
public static final int KEYCODE_SYM = 63;
public static final int KEYCODE_EXPLORER = 64;
public static final int KEYCODE_ENVELOPE = 65;
public static final int KEYCODE_ENTER = 66;
public static final int KEYCODE_DEL = 67;
public static final int KEYCODE_GRAVE = 68;
public static final int KEYCODE_MINUS = 69;
public static final int KEYCODE_EQUALS = 70;
actionNone : 回车键,按下后光标到下一行
actionSend : Send
actionNext : Next
![](http://images.cnitblog.com/blog/363274/201309/05150622-410008ad4fda47db8808c5ef5574b9b7.jpg)
actionDone : Done,隐藏软键盘,即使不是最后一个文本输入框
设置android:imeOptions="actionDone" 可能监听不到键盘的是事件KeyEvent.KEYCODE_DPAD_CENTER 或者KeyEvent.KEYCODE_ENTER事件
可以 实现 setOnEditorActionListener 的onEditorAction
在EditorInfo的说明中能够找到。列举如下:
IME_ACTION_DONE |
IME_ACTION_GO |
IME_ACTION_NEXT |
IME_ACTION_NONE |
IME_ACTION_PREVIOUS |
IME_ACTION_SEARCH |
IME_ACTION_SEND |
IME_ACTION_UNSPECIFIED |
actionUnspecified 未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.效果:
![](http://dl.iteye.com/upload/attachment/355737/bd9d7b7c-2a93-37b3-afd9-cda2f3593058.png)
actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE 效果:
![](http://dl.iteye.com/upload/attachment/355737/bd9d7b7c-2a93-37b3-afd9-cda2f3593058.png)
actionGo 去往,对应常量EditorInfo.IME_ACTION_GO 效果:
![](http://dl.iteye.com/upload/attachment/355757/a8db4447-ec91-39aa-a546-c117db16cf55.png)
actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH 效果:
![](http://dl.iteye.com/upload/attachment/355769/c35d6b78-d5b9-314a-9698-144bc12d0af3.png)
actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND 效果:
![](http://dl.iteye.com/upload/attachment/355788/c168252f-bb3d-3831-8e3c-8bced16b12a1.png)
actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT 效果:
![](http://dl.iteye.com/upload/attachment/355798/aa6bd8b1-8ab3-38d9-b162-01ce10f4f998.png)
actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE 效果:
![](http://dl.iteye.com/upload/attachment/355804/79979746-7373-3377-bb7e-3dd4bdede464.png)
private TextView.OnEditorActionListener mWriteListener =
new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
// If the action is a key-up event on the return key, send the message
if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_UP) {
String message = view.getText().toString();
sendMessage(message);
}
if(D) Log.i(TAG, "END onEditorAction");
return true;
}
};
public static final int KEYCODE_SHIFT_RIGHT = 60;
public static final int KEYCODE_TAB = 61;
public static final int KEYCODE_SPACE = 62;
public static final int KEYCODE_SYM = 63;
public static final int KEYCODE_EXPLORER = 64;
public static final int KEYCODE_ENVELOPE = 65;
public static final int KEYCODE_ENTER = 66;
public static final int KEYCODE_DEL = 67;
public static final int KEYCODE_GRAVE = 68;
public static final int KEYCODE_MINUS = 69;
public static final int KEYCODE_EQUALS = 70;
相关文章推荐
- android:imeOptions="actionDone"无效
- 记一次,软键盘设置android:imeOptions="actionDone"在华为手机上无效的坑
- 【Android】设置android:maxLines="1"后,android:imeOptions="actionSearch"失效
- Android Edittext设置android:imeOptions="actionSearch"不起作用
- Android edittext 输入框 下一项 android:imeOptions="actionNext"
- EditText添加android:imeOptions="actionSearch"弹出的键盘中带有搜索按钮
- Android Edittext设置android:imeOptions="actionSearch"不起作用
- Android edittext 输入框 下一项 android:imeOptions="actionNext"
- EditText的imeOptions="actionNext"属性无效
- android:android:imeOptions="flagNoExtractUi"
- EditText设置android:imeOptions="actionSend"无效问题
- android:imeOptions属性详解以及无效处理
- app:showAsAction=""与android:showAsAction=""的区别
- 关于Android 中 一个错误的解决办法 “Do not request Window.FEATURE_ACTION_BAR....."
- 通过设置android:imeOptions来改变软键盘Enter键图标
- android:showAsAction = "never"那么这句话是做什么用的呢
- 设置EditText的android:imeOptions来改变软键盘Enter键图标
- Android EditText inputType imeOptions 属性
- android:imeOptions属性 (转载)
- androidEditTextinputType及android:imeOptions=”actionDone”(转)