I have a FAB on a Fragment in a ViewPager2
which should respect the window insets when going edge-to-edge. I'm adding a OnApplyWindowInsetsListener
on the FAB which updates its margin. This works fine when using the old ViewPager
.
When updating to ViewPager2
it seems like the OnApplyWindowInsetsListener
is not called at the beginning. It is though, when I start the ActionMode
. Then, the listener is called and the new margin is used until I leave parent Fragment.
I've forked the demo project to illustrate the problem. See "ViewPager2 with Nested RecyclerViews" example (ParallelNestedScrollingActivity
) on the branch edge-to-edge
on https://github.com/hardysim/views-widgets-samples/tree/edge-to-edge .
In here, I've added a FAB to the (nested) RecyclerView
used on a ViewPager2-page and set the Activity-UI to edge-to-edge (see View.goEdgeToEdge()
). Then, the FAB is behind the navigation bar we need to update its margin to add the window insets.
And this is where it's not working (but it works fine with the old ViewPager
).
This has been answered in the issue tracker where it was originally asked:
So I've created a little helper
which is called right after calling
ViewCompat.setOnApplyWindowInsetsListener()
on aView
: