hide virtual keyboard in android?

后端 未结 4 829
情深已故
情深已故 2021-01-25 08:08

Hi i won\'t want to show virtual keyboard even user touch the editText field.

4条回答
  •  被撕碎了的回忆
    2021-01-25 08:43

    try this

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        boolean ret = super.dispatchTouchEvent(event);
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(mCurretnView.getWindowToken(), 0);  
        return ret;
    }
    

    or

    editText.setOnTouchListener(new View.OnTouchListener() {
    
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mCurretnView.getWindowToken(), 0);  
            return false;
        }
    });
    

提交回复
热议问题