把EditText的Ime Options属性设置成不同的值,Enter键上可以显示不同的文字或图案
actionNone : 回车键,按下后光标到下一行
actionSend : Send
actionNext : Next

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

软键盘的Enter键默认显示的是“完成”文本,我们知道按Enter建表示前置工作已经准备完毕了,要去什么什么啦。比如,在一个搜索中,我们输入要搜索的文本,然后按Enter表示要去搜索了,但是默认的Enter键显示的是“完成”文本,看着不太合适,不符合搜索的语义,如果能显示“搜索”两个字或者显示一个表示搜索的图标多好。事实证明我们的想法是合理的,Android也为我们提供的这样的功能。通过设置android:imeOptions来改变默认的“完成”文本。这里举几个常用的常量值:

  1. actionUnspecified  未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.效果:
  2. actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE 效果:
  3. actionGo 去往,对应常量EditorInfo.IME_ACTION_GO 效果:
  4. actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH 效果: 
  5. actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND 效果:
  6. actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT 效果:
  7. actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE 效果:

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;

最新文章

  1. 冒泡排序和用for循环画菱形
  2. Android登录界面实现
  3. C++ 中 ZeroMemory、memset 危险需慎用
  4. HTML5 WebSocket 实时推送信息测试demo
  5. leetcode 41 First Missing Positive ---java
  6. Mac + IDEA + JRebel破解方法.
  7. samba常用命令
  8. Openstack命令收集
  9. mac+phpstorm增加xdebug调试
  10. 打造基于Clang LibTooling的iOS自动打点系统CLAS(二)
  11. python 魔法方法(学习过程的笔记)
  12. mac系统webstorm快捷键
  13. SQL server Error Number
  14. java8 - IO
  15. 软件性能测试技术树(二)----Linux服务器性能
  16. 正则表达式(特殊字符)/Xpath语法/CSS选择器
  17. rqalpha环境搭建(windows版)
  18. delphi 小数点四舍五入问题
  19. [转]OpenGL 使用 PBO 高速复制屏幕图像到内存或者纹理中
  20. 【工具】Windows7搭建FTP服务器

热门文章

  1. HDFS镜像文件fsimage和编辑日志文件edits
  2. java_第一年_JDBC(6)
  3. 51nod - 1586 - 约数和 - 打表 - 思维
  4. 从安装linux(centos7.6)系统到部署springboot java程序到k8s(大纲)
  5. 使用JS增加标签
  6. C#设计模式:迭代器模式(Iterator Pattern)
  7. JQ的简单使用(基础)——————JQ
  8. 案例 element 表单名两端对齐
  9. C# 实现实体类和Xml转换
  10. xcopy忽略文件 7zip打包