“I understand that the default navigation bar can be turned on or off depending on the device settings. I want to set an appropriate height for a custom navigation bar in both scenarios.”
For example:
If the custom navigation bar height is 50px:
When the default navigation bar is on: 50px + 48px
When the default navigation bar is off: 50px
thanks
- using
- kotlin
- compose
- API 30 (R, Android 11.0)
i tried
val hasSoftKey = ViewConfiguration.get().hasPermanentMenuKey()
fun Activity.isNavigationBarVisible(): Boolean {
val decorView = window.decorView as ViewGroup
var isNavBarVisible = false
decorView.setOnHierarchyChangeListener(object : ViewGroup.OnHierarchyChangeListener {
override fun onChildViewAdded(parent: View?, child: View?) {
isNavBarVisible = isNavigationBarPresent(child)
}
override fun onChildViewRemoved(parent: View?, child: View?) {}
})
return isNavBarVisible
}
private fun isNavigationBarPresent(view: View?): Boolean {
return view?.id != View.NO_ID && view?.resources?.getResourceName(view.id)?.contains("navigationBarBackground") == true
}