Android积木之 点击空白区域隐藏小键盘

  override fun onTouchEvent(event: MotionEvent?): Boolean {
        val manager =
            this.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        if (event?.getAction() === MotionEvent.ACTION_DOWN) {
            if (this.getCurrentFocus() != null && this.getCurrentFocus().getWindowToken() != null) {
                manager.hideSoftInputFromWindow(
                    this.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS
                )
            }
        }
        return super.onTouchEvent(event)
    }

 

你可能感兴趣的:(Android积木)