Google is committed to advancing racial equity for Black communities. See how.

WindowInsetsControllerCompat

class WindowInsetsControllerCompat
kotlin.Any
   ↳ androidx.core.view.WindowInsetsControllerCompat

Provide simple controls of windows that generate insets. For SDKs >= 30, this class is a simple wrapper around WindowInsetsController. For lower SDKs, this class aims to behave as close as possible to the original implementation.

Summary

Constants
static Int

Option for setSystemBarsBehavior(int): Window would like to remain interactive when hiding navigation bars by calling hide(int) or WindowInsetsAnimationController#setInsetsAndAlpha(Insets, float, float).

static Int

The default option for setSystemBarsBehavior(int).

static Int

Option for setSystemBarsBehavior(int): Window would like to remain interactive when hiding navigation bars by calling hide(int) or WindowInsetsAnimationController#setInsetsAndAlpha(Insets, float, float).

Public constructors
<init>(@NonNull window: Window, @NonNull view: View)

Public methods
Int

Retrieves the requested behavior of system bars.

Unit
hide(types: Int)

Makes a set of windows causing insets disappear.

Boolean

Checks if the foreground of the navigation bar is set to light.

Boolean

Checks if the foreground of the status bar is set to light.

Unit

If true, changes the foreground color of the navigation bars to light so that the items on the bar can be read clearly.

Unit

If true, changes the foreground color of the status bars to light so that the items on the bar can be read clearly.

Unit

Controls the behavior of system bars.

Unit
show(types: Int)

Makes a set of windows that cause insets appear on screen.

static WindowInsetsControllerCompat

Wrap a WindowInsetsController into a WindowInsetsControllerCompat for compatibility purpose.

Constants

BEHAVIOR_SHOW_BARS_BY_SWIPE

static val BEHAVIOR_SHOW_BARS_BY_SWIPE: Int

Option for setSystemBarsBehavior(int): Window would like to remain interactive when hiding navigation bars by calling hide(int) or WindowInsetsAnimationController#setInsetsAndAlpha(Insets, float, float).

When system bars are hidden in this mode, they can be revealed with system gestures, such as swiping from the edge of the screen where the bar is hidden from.

Value: 1

BEHAVIOR_SHOW_BARS_BY_TOUCH

static val BEHAVIOR_SHOW_BARS_BY_TOUCH: Int

The default option for setSystemBarsBehavior(int). System bars will be forcibly shown on any user interaction on the corresponding display if navigation bars are hidden by hide(int) or WindowInsetsAnimationController#setInsetsAndAlpha(Insets, float, float).

Value: 0

BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE

static val BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE: Int

Option for setSystemBarsBehavior(int): Window would like to remain interactive when hiding navigation bars by calling hide(int) or WindowInsetsAnimationController#setInsetsAndAlpha(Insets, float, float).

When system bars are hidden in this mode, they can be revealed temporarily with system gestures, such as swiping from the edge of the screen where the bar is hidden from. These transient system bars will overlay app’s content, may have some degree of transparency, and will automatically hide after a short timeout.

Value: 2

Public constructors

<init>

WindowInsetsControllerCompat(
    @NonNull window: Window,
    @NonNull view: View)

Public methods

getSystemBarsBehavior

fun getSystemBarsBehavior(): Int

Retrieves the requested behavior of system bars.

Return
Int the system bar behavior controlled by this window.

hide

fun hide(types: Int): Unit

Makes a set of windows causing insets disappear.

Note that if the window currently doesn't have control over a certain type, it will apply the change as soon as the window gains control. The app can listen to the event by observing View#onApplyWindowInsets and checking visibility with WindowInsets#isVisible.

Parameters
types Int: A bitmask of WindowInsetsCompat.Type specifying what windows the app would like to make disappear.

isAppearanceLightNavigationBars

fun isAppearanceLightNavigationBars(): Boolean

Checks if the foreground of the navigation bar is set to light.

This method always returns false on API < 26.

Return
Boolean true if the foreground is light

isAppearanceLightStatusBars

fun isAppearanceLightStatusBars(): Boolean

Checks if the foreground of the status bar is set to light.

This method always returns false on API < 23.

Return
Boolean true if the foreground is light

setAppearanceLightNavigationBars

fun setAppearanceLightNavigationBars(isLight: Boolean): Unit

If true, changes the foreground color of the navigation bars to light so that the items on the bar can be read clearly. If false, reverts to the default appearance.

This method has no effect on API < 26.

setAppearanceLightStatusBars

fun setAppearanceLightStatusBars(isLight: Boolean): Unit

If true, changes the foreground color of the status bars to light so that the items on the bar can be read clearly. If false, reverts to the default appearance.

This method has no effect on API < 23.

setSystemBarsBehavior

fun setSystemBarsBehavior(behavior: Int): Unit

Controls the behavior of system bars.

Parameters
behavior Int: Determines how the bars behave when being hidden by the application.

show

fun show(types: Int): Unit

Makes a set of windows that cause insets appear on screen.

Note that if the window currently doesn't have control over a certain type, it will apply the change as soon as the window gains control. The app can listen to the event by observing View#onApplyWindowInsets and checking visibility with WindowInsets#isVisible.

Parameters
types Int: A bitmask of WindowInsetsCompat.Type specifying what windows the app would like to make appear on screen.

toWindowInsetsControllerCompat

@NonNull @RequiresApi(30) static fun toWindowInsetsControllerCompat(@NonNull insetsController: WindowInsetsController): WindowInsetsControllerCompat

Wrap a WindowInsetsController into a WindowInsetsControllerCompat for compatibility purpose.

Parameters
insetsController WindowInsetsController: The WindowInsetsController to wrap.
Return
WindowInsetsControllerCompat The provided WindowInsetsControllerCompat wrapped into a WindowInsetsControllerCompat