打开抽屉时禁用底层片段

问题描述

嘿,

在我的应用中,我有一个抽屉。打开后,基础片段中的editText仍然有效。有谁知道我该如何解决

enter image description here

在红色箭头处是editText,当打开抽屉时,该文本不应立即响应。

x

解决方法

一种非常简单的方法是隐藏键盘,然后打开抽屉。使键盘再次显示的唯一方法是单击edittext。

这里是隐藏它的一种方法:

fun hideKeyboard(activity: Activity) {
    val imm = activity.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
    //Find the currently focused view,so we can grab the correct window token from it.
    var view: View? = activity.currentFocus
    //If no view currently has focus,create a new one,just so we can grab a window token from it
    if (view == null) {
        view = View(activity)
    }
    imm.hideSoftInputFromWindow(view.windowToken,0)
}