当前位置: 代码迷 >> 综合 >> android优雅管理edittext得输入法
  详细解决方案

android优雅管理edittext得输入法

热度:83   发布时间:2024-01-21 18:11:02.0

android优雅管理edittext得输入法

 public boolean dispatchTouchEvent(MotionEvent event) {View v = getCurrentFocus();boolean ret = super.dispatchTouchEvent(event);if (v instanceof EditText) {View currentFocus = getCurrentFocus();int screenCoords[] = new int[2];currentFocus.getLocationOnScreen(screenCoords);float x = event.getRawX() + currentFocus.getLeft() - screenCoords[0];float y = event.getRawY() + currentFocus.getTop() - screenCoords[1];if (event.getAction() == MotionEvent.ACTION_UP&& (x < currentFocus.getLeft() ||x >= currentFocus.getRight() ||y < currentFocus.getTop() ||y > currentFocus.getBottom())) {InputMethodManager imm =(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);}}return ret;}


  相关解决方案