The best way to click and hide the soft keyboard in Android

Implementation function: Click EditText, the soft keyboard will appear and will not be hidden. Click or touch any area other than EditText, and the soft keyboard will be hidden;

1. Override the dispatchtouchevent() method to get the soft keyboard hidden when the current touch event is down

@Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    //Finger touch screen event
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
      // get current focus,Generally it is EditText
      View view = getCurrentFocus();
      if (isShouldHideSoftKeyBoard(view,ev)) {
        hideSoftKeyBoard(view.getWindowToken());
      }
    }
    return super.dispatchTouchEvent(ev);
  }

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>