Android中点击事件之KeyListener实现步骤

  1. 编写布局
     
    
  2. 设置事件
     etEmail.setKeyListener(new KeyListener() {
                @Override
                public int getInputType() {
                    return 0;
                }
                @Override
                public boolean onKeyDown(View view, Editable text, int keyCode, KeyEvent event) {
                    return false;
                }
                @Override
                public boolean onKeyUp(View view, Editable text, int keyCode, KeyEvent event) {
                    return false;
                }
                @Override
                public boolean onKeyOther(View view, Editable text, KeyEvent event) {
                    return false;
                }
                @Override
                public void clearMetaKeyState(View view, Editable content, int states) {
    
                }
            });
    
  3. 处理事件
     etEmail.setKeyListener(new KeyListener() {
                @Override
                public int getInputType() {
                    return 0;
                }
                @Override
                public boolean onKeyDown(View view, Editable text, int keyCode, KeyEvent event) {
                    Log.i(TAG, "处理按键事件");
    		      return false;
                }
                @Override
                public boolean onKeyUp(View view, Editable text, int keyCode, KeyEvent event) {
                    return false;
                }
                @Override
                public boolean onKeyOther(View view, Editable text, KeyEvent event) {
                    return false;
                }
                @Override
                public void clearMetaKeyState(View view, Editable content, int states) {
    
                }
            });
    
  4. 查看效果
    在这里插入图片描述

你可能感兴趣的:(Android,Android开发从入门到精通)