Android 监听软键盘点击回车及换行事件

mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {  
              
            @Override  
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {  
                //当actionId == XX_SEND 或者 XX_DONE时都触发  
                //或者event.getKeyCode == ENTER 且 event.getAction == ACTION_DOWN时也触发  
                //注意,这是一定要判断event != null。因为在某些输入法上会返回null。  
                if (actionId == EditorInfo.IME_ACTION_SEND  
                        || actionId == EditorInfo.IME_ACTION_DONE  
                        || (event != null && KeyEvent.KEYCODE_ENTER == event.getKeyCode() && KeyEvent.ACTION_DOWN == event.getAction())) {  
                    //处理事件  
                }  
                return false;  
            }  
        });  

 

posted @ 2017-04-05 16:44  星辰之力  阅读(14012)  评论(0编辑  收藏  举报