Prevent the keyboard from displaying on activity start

后端 未结 17 831
轮回少年
轮回少年 2020-11-30 17:26

I have an activity with an Edit Text input. When the activity is initialized, the Android keyboard is shown. How can the keyboard remain hidden until the user

17条回答
  •  我在风中等你
    2020-11-30 17:37

    just add this on your Activity:

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
          if (getCurrentFocus() != null) {
               InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
               imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
          }
          return super.dispatchTouchEvent(ev);
    }
    

提交回复
热议问题