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

    xiaoxiao2023-03-15  5

    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;               }           });  
    转载请注明原文地址: https://ju.6miu.com/read-1151881.html
    最新回复(0)