2

After Android 10, users can prefer gesture navigation mode. I want to detect whether the device in gesture navigation mode or not. I will change the design with respect to system navigation preference.

I can't find anything in documentation. How to do it?

Do you have any official API or workaround?

Aaydin
  • 192
  • 1
  • 6
  • I need to know as well. The gesture navigation seems to add a little line at the bottom of the screen, taking up some real-estate. I need to take this into account for my layouts. – SMBiggs Jan 25 '23 at 20:53
  • Possible answer in https://stackoverflow.com/q/74091225/556600 – SoftWyer Mar 22 '23 at 18:23

1 Answers1

0

From Android 30 onwards we can get system insets to check whether gesture navigation is enabled or not.

If gesture navigation is enabled, then WindowInsets.Type.systemGestures() will have values for inset.left and inset.right greater than 0.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            binding.root.apply {
                var hasGesture = false
                doOnAttach {
                    val inset = it.rootWindowInsets?.getInsets(WindowInsets.Type.systemGestures())
                    println("inset: left: ${inset?.left} right: ${inset?.right} top:${inset?.top} bottom: ${inset?.bottom}")
                    val margin = it.rootWindowInsets?.getInsets(WindowInsets.Type.systemGestures())?.left ?: 0
                    hasGesture = margin > 0
                }
            }
        }
vikoo
  • 2,451
  • 20
  • 27