在Fragment中有时候软键盘隐藏失败
最大的可能是焦点被抢,导致隐藏失败。
最佳做法:失去焦点之前就隐藏键盘,如果需要后边再弹出
弹出失败
原因太多
解决方式 直接post可以解决:
v.editEext.post{
val view = v.inputVCodeEdt.getEditText() view.requestFocus() SoftInputUtils.showSoftInput(requireContext(), view)
}
隐藏失败
原因:焦点被抢,
解决方式:失去焦点之前就隐藏键盘,如果需要后边再弹出
v.editEext.apply { setOnVerifyCodeListener(object : OnVerifyCodeListener { override fun onTextChanged(code: String) { } override fun onComplete(code: String) { if (code.contentEquals(args.code)) { SoftInputUtils.hideSoftInput(requireActivity()) } else { } } }) }