Android 隐藏键盘只会使键盘半透明/褪色

Android 隐藏键盘只会使键盘半透明/褪色,android,kotlin,Android,Kotlin,我正在使用此代码隐藏一个键盘,使其不受DialogFragment的影响 etCustomerLookup.hideKeyboard() 分机 fun View.hideKeyboard() { val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager imm.hideSoftInputFromWindow(windowToken, 0) } 这就是我看到的

我正在使用此代码隐藏一个键盘,使其不受DialogFragment的影响

etCustomerLookup.hideKeyboard()
分机

fun View.hideKeyboard() {
    val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
    imm.hideSoftInputFromWindow(windowToken, 0)
}
这就是我看到的


更新:即使在注释掉hideKeyboard()行之后,它也没有改变任何东西,仍然得到褪色的键盘。另一个注意事项-褪色键盘下的所有按钮仍然可以访问

我认为您使用的是出现在键盘顶部的窗口,因为您的视图具有透明度,所以会发生这种情况。

请尝试这两种方法

    fun hideKeyboard(activity: Activity) {
        val imm: InputMethodManager = activity.getSystemService(AppCompatActivity.INPUT_METHOD_SERVICE) as InputMethodManager
        //Find the currently focused view, so we can grab the correct window token from it.
        var 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)
    }

    fun hideKeyboardFromWindow(activity: Activity) {
        val view = activity.findViewById<View>(R.id.content)
        if (view != null) {
            val imm = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.hideSoftInputFromWindow(view.windowToken, 0)
        }
    }
fun隐藏板(活动:活动){
val imm:InputMethodManager=activity.getSystemService(AppCompatActivity.INPUT\u方法\u服务)作为InputMethodManager
//找到当前聚焦的视图,这样我们就可以从中获取正确的窗口标记。
var view=activity.currentFocus
//如果当前没有视图有焦点,创建一个新的,这样我们就可以从中获取一个窗口标记
如果(视图==null){
视图=视图(活动)
}
imm.hideSoftInputFromWindow(view.windowToken,0)
}
趣味隐藏板FromWindow(活动:活动){
val视图=activity.findViewById(R.id.content)
如果(视图!=null){
val imm=activity.getSystemService(Context.INPUT\u METHOD\u SERVICE)作为InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken,0)
}
}

绝对奇怪。你能在其他设备和模拟器上重现这种行为吗?它可能与你正在使用的特定android皮肤或键盘应用程序有关?那是什么类型的键盘?你试过其他设备吗?你用什么键盘?从未在
DialogFragment
s中看到过这种行为。
DialogFragment
是半透明的吗?它能自己截图(带键盘)并画图吗?我不使用任何显示在键盘上的视图。我正在显示一个对话框,其中有一个autosuggest edittext,当用户选择一个建议时,该对话框将被取消,键盘将从完全可见变为半透明。尝试了这两种方法。没有。请详细说明您的情况。