Detect soft navigation bar availability in android device progmatically?

后端 未结 7 1484
礼貌的吻别
礼貌的吻别 2020-12-02 18:50

I am trying to determine soft navigation bar through the android program. I didn\'t find straight way to determine. Is there anyway to find the navigation bar availability.

7条回答
  •  臣服心动
    2020-12-02 19:21

    Other answers don't help me. But it's quite useful to know if navigation bar is shown, especially after Android P/Q, where user can swipe it out of screen. I've encounter this article https://blog.stylingandroid.com/gesture-navigation-window-insets/ and made such method

    fun hasNavBar(activity: Activity): Boolean {
        val temporaryHidden = activity.window.decorView.visibility and View.SYSTEM_UI_FLAG_HIDE_NAVIGATION != 0
        if (temporaryHidden) return false
        val decorView = activity.window.decorView
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            decorView.rootWindowInsets?.let{
                return it.stableInsetBottom != 0
            }
        }
        return true
    }
    

提交回复
热议问题