setOnApplyWindowInsetsListener never called

Belgikoi picture Belgikoi · Jan 6, 2019 · Viewed 10.9k times · Source

I would like to calculate the navigationBar height. I've seen this presentation : https://chris.banes.me/talks/2017/becoming-a-master-window-fitter-nyc/

So, I tried to use the method View.setOnApplyWindowInsetsListener(). But, for some reason, it's never called.

Does anyone knows why ? Any limitation there ?

I've tried to use it like this :

navBarOverlay.setOnApplyWindowInsetsListener { v, insets -> 
   Timber.i("BOTTOM = ${insets.systemWindowInsetBottom}")
   return@setOnApplyWindowInsetsListener insets
}

Note that my root layout is a ConstraintLayout.

Answer

KevinRyu picture KevinRyu · Nov 21, 2019

I faced the same issue.

If your root view is ConstraintLayout and contains android:fitsSystemWindows="true" attr, the view consumed onApplyWindowInsets callbacks. So if you set onApplyWindowInsets on child views, they never get onApplyWindowInsets callbacks.

Or check your parent views consume the callback.