# WindowInsetsApplier

Artifact: [androidx.viewpager2:viewpager2](https://developer.android.com/jetpack/androidx/releases/viewpager2)  
[View Source](https://cs.android.com/search?q=file:androidx/viewpager2/widget/WindowInsetsApplier.java+class:androidx.viewpager2.widget.WindowInsetsApplier)  
Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager2#1.1.0)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/viewpager2/widget/WindowInsetsApplier "View this page in Java")


```
class WindowInsetsApplier : OnApplyWindowInsetsListener
```

<br />

*** ** * ** ***

An [OnApplyWindowInsetsListener](https://developer.android.com/reference/kotlin/androidx/core/view/OnApplyWindowInsetsListener) that applies [WindowInsets](https://developer.android.com/reference/kotlin/androidx/core/view/WindowInsetsCompat) to all children of a [ViewPager2](https://developer.android.com/reference/kotlin/androidx/viewpager2/widget/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](https://developer.android.com/reference/kotlin/androidx/viewpager2/widget/WindowInsetsApplier#install(androidx.viewpager2.widget.ViewPager2)) 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](https://developer.android.com/reference/kotlin/androidx/viewpager2/widget/WindowInsetsApplier#install(androidx.viewpager2.widget.ViewPager2)) will do nothing. None of the above described effects will happen.

## Summary

| ### Public functions |
|---|---|
| `java-static `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [install](https://developer.android.com/reference/kotlin/androidx/viewpager2/widget/WindowInsetsApplier#install(androidx.viewpager2.widget.ViewPager2))`(viewPager: `[ViewPager2](https://developer.android.com/reference/kotlin/androidx/viewpager2/widget/ViewPager2)`)` Installs a [WindowInsetsApplier](https://developer.android.com/reference/kotlin/androidx/viewpager2/widget/WindowInsetsApplier) into the given ViewPager2, but only when window insets dispatching hasn't been fixed in the current run configuration. |
| [WindowInsetsCompat](https://developer.android.com/reference/kotlin/androidx/core/view/WindowInsetsCompat) | [onApplyWindowInsets](https://developer.android.com/reference/kotlin/androidx/viewpager2/widget/WindowInsetsApplier#onApplyWindowInsets(android.view.View,androidx.core.view.WindowInsetsCompat))`(v: `[View](https://developer.android.com/reference/android/view/View.html)`, insets: `[WindowInsetsCompat](https://developer.android.com/reference/kotlin/androidx/core/view/WindowInsetsCompat)`)` When [set](https://developer.android.com/reference/kotlin/androidx/core/view/ViewCompat#setOnApplyWindowInsetsListener(android.view.View,androidx.core.view.OnApplyWindowInsetsListener)) on a View, this listener method will be called instead of the view's own `onApplyWindowInsets` method. |

## Public functions

### install

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager2#1.1.0)  

```
java-static fun install(viewPager: ViewPager2): Boolean
```

Installs a [WindowInsetsApplier](https://developer.android.com/reference/kotlin/androidx/viewpager2/widget/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  

| Parameters |
|---|---|
| `viewPager: `[ViewPager2](https://developer.android.com/reference/kotlin/androidx/viewpager2/widget/ViewPager2) | The ViewPager2 to install the WindowInsetsApplier into |

| Returns |
|---|---|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether or not the WindowInsetsApplier was installed |

### onApplyWindowInsets

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager2#1.1.0)  

```
fun onApplyWindowInsets(v: View, insets: WindowInsetsCompat): WindowInsetsCompat
```

When [set](https://developer.android.com/reference/kotlin/androidx/core/view/ViewCompat#setOnApplyWindowInsetsListener(android.view.View,androidx.core.view.OnApplyWindowInsetsListener)) on a View, this listener method will be called instead of the view's own `onApplyWindowInsets` method.

Note: When running on devices with API Level 29 or before, this might not be called when the IME inset is changed if the soft input mode of the window is not [SOFT_INPUT_ADJUST_RESIZE](https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#SOFT_INPUT_ADJUST_RESIZE()).  

| Parameters |
|---|---|
| `v: `[View](https://developer.android.com/reference/android/view/View.html) | The view applying window insets |
| `insets: `[WindowInsetsCompat](https://developer.android.com/reference/kotlin/androidx/core/view/WindowInsetsCompat) | The insets to apply |

| Returns |
|---|---|
| [WindowInsetsCompat](https://developer.android.com/reference/kotlin/androidx/core/view/WindowInsetsCompat) | The insets supplied, minus any insets that were consumed |