editText中设置回车输入不换行

editText中设置回车输入不换行

        这是源码 Mms 编辑界面所使用的一个效果,在信息正文的编辑框里输入回车是不会实现换行的,实现代码如下,也许有时候你也有这样的需求。

    1. Activtyy 实现TextView.OnEditorActionListener这个接口
    2. public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    3. if (event != null) {
    4. // if shift key is down, then we want to insert the '\n' char in the TextView; 注意看下注释
    5. // otherwise, the default action is to send the message.
    6. if (!event.isShiftPressed()) {
    7. return true;
    8. }
    9. return false;
    10. }





posted @ 2016-10-01 11:31  杨伟乔  阅读(897)  评论(0编辑  收藏  举报