Android enter键发送消息
2014-10-08 14:49
281 查看
在开发聊天App是通常会有enter键发送消息的需求,使用Enter键发送消息其实就是要改变EditText的
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了!
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异常处理发送消息给服务器
- Android: 如何利用Handler处理和发送消息来实现页面刷新的功能
- 基于mina服务器框架在android客户端接中文收不到消息以及发送不出中文的的问题
- Android 模拟按键发送消息
- Android基于XMPP Smack Openfire开发IM【三】客户端接收服务器发送的消息
- android handler发送消息需要注意的地方
- Android基于XMPP Smack Openfire下学习开发IM(四)单人聊天和多人聊天(发送消息、接收消息)
- 【笔记】ROSjava-android控制ROS机器人——ROSjava消息发送的解密
- android状态栏消息发送
- Android 程式开发:(廿一)消息传递 —— 21.3 使用Intent发送短信
- android发送消息正确方式
- android 里使用Socket进行发送消息案例
- Android 开发即时聊天工具 YQ :(五) 发送消息
- android 发送通知栏消息,点击后打开指定网页
- android应用程序消息处理机制之消息发送
- Android学习—— Handler 的消息发送,在新的线程处理消息
- Android 主线程和线程之间相互发送消息
- 如何处理在android中有来电就给来电用户发送一个消息?
- Android 主线程和线程之间相互发送消息
- 基于mina服务器框架在android客户端接中文收不到消息以及发送不出中文的的问题