Edittext点击外部区域隐藏软件盘12345678910111213binding.root.setOnTouchListener { _, event -> if (event.action == MotionEvent.ACTION_DOWN) { val focusedView: View? = activity?.currentFocus if (focusedView is EditText) { // 如果当前焦点在EditText上,并且点击位置不在EditText范围内,隐藏键盘 if (event.x < focusedView.getLeft() || event.x > focusedView.getRight() || event.y < focusedView.getTop() || event.y > focusedView.getBottom()) { hideSoftInput() } } } false}