【问题标题】:Disable underlyingFragment when Drawer is opened打开抽屉时禁用底层Fragment
【发布时间】:2020-10-07 14:25:52
【问题描述】:

嘿,

在我的应用程序中,我有一个抽屉。当它打开时,来自底层片段的 editText 仍然有效。有谁知道我该如何解决这个问题?

红色箭头处是一个editText,当抽屉打开时,它现在不应该响应。

x

【问题讨论】:

    标签: java android fragment android-fragmentactivity drawer


    【解决方案1】:

    一个非常简单的方法是隐藏键盘然后抽屉打开。让键盘再次显示的唯一方法是单击编辑文本。

    这是隐藏它的一种方法:

    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)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-11
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2019-04-04
      • 2021-02-28
      相关资源
      最近更新 更多