您的位置:首页 > 移动开发 > Android开发

Android enter键发送消息

2014-10-08 14:49 281 查看
   在开发聊天App是通常会有enter键发送消息的需求,使用Enter键发送消息其实就是要改变EditText的
imeOptions
属性,可以使用
setImeOptions (int imeOptions)方法来设定,也是使用xml来设置,具体有下列属性值可设置,其中IME_ACTION_DONE 是完成,IME_ACTION_SEND 发送,其余的就不一一解释,感兴趣的可以去试试。


很显然我们需要的是IME_ACTION_SEND,下列是使用实例:edit.setImeOptions(EditorInfo.IME_ACTION_DONE);
edit.setSingleLine(true);
setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
CommonUtils.hideSoftInput((Activity) getContext());
if (!TextUtils.isEmpty(edit.getText().toString().trim())) {
sendText();
}
return true;
}
return false;
}
});是不是很简单呢,对就是这么简单,多注意细节就OK了!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android 聊天 EditText