WindowInsetsApplier
class WindowInsetsApplier : OnApplyWindowInsetsListener
An OnApplyWindowInsetsListener that applies WindowInsets to all children of a ViewPager2, making sure they all receive the same insets regardless of whether any of them consumed any insets.
To prevent the ViewPager2 itself from dispatching the insets incorrectly, this listener will consume all insets it applies. As a consequence, siblings of ViewPager2, or siblings of its parents, to whom the WindowInsets haven't yet been dispatched, won't receive them at all. If you require those views to receive the WindowInsets, do not set this listener on ViewPager2 and do not consume insets in any of the pages.
Call install to install this listener in ViewPager2.
When running on API 30 or higher and the targetSdkVersion is set to API 30 or higher, the fix is not needed and install will do nothing. None of the above described effects will happen.
Summary
Public functions |
|
|---|---|
java-static Boolean |
install(viewPager: ViewPager2)Installs a |
WindowInsetsCompat |
onApplyWindowInsets(v: View, insets: WindowInsetsCompat)When |
Public functions
install
java-static fun install(viewPager: ViewPager2): Boolean
Installs a WindowInsetsApplier into the given ViewPager2, but only when window insets dispatching hasn't been fixed in the current run configuration. It will return whether or not the WindowInsetsApplier was installed.
Window insets dispatching is fixed on Android SDK R, but the targetSdk of the app also needs to be set to R or higher. If both these conditions hold, the WindowInsetsApplier won't be installed. If either we're running on SDK The ViewPager2 to install the WindowInsetsApplier into Whether or not the WindowInsetsApplier was installed
Parameters
viewPager: ViewPager2
Returns
Boolean
onApplyWindowInsets
fun onApplyWindowInsets(v: View, insets: WindowInsetsCompat): WindowInsetsCompat
When set on a View, this listener method will be called instead of the view's own onApplyWindowInsets method.
| Parameters | |
|---|---|
v: View |
The view applying window insets |
insets: WindowInsetsCompat |
The insets to apply |
| Returns | |
|---|---|
WindowInsetsCompat |
The insets supplied, minus any insets that were consumed |