WindowInsetsController | API reference | Android Developers (original) (raw)
public interface WindowInsetsController
``
android.view.WindowInsetsController
Interface to control windows that generate insets. For guidance, see Hide system bars for immersive mode.
Summary
Nested classes | |
---|---|
interface | WindowInsetsController.OnControllableInsetsChangedListener Listener to be notified when the set of controllable WindowInsets.Type controlled by a WindowInsetsController changes. |
Constants | |
---|---|
int | APPEARANCE_LIGHT_CAPTION_BARS When WindowInsetsController.APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND is set, changes the foreground color of the caption bars so that the items on the bar can be read clearly on light backgrounds. |
int | APPEARANCE_LIGHT_NAVIGATION_BARS Changes the foreground color for light navigation bars so that the items on the bar can be read clearly. |
int | APPEARANCE_LIGHT_STATUS_BARS Changes the foreground color for light status bars so that the items on the bar can be read clearly. |
int | APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND Makes the caption bar transparent. |
int | BEHAVIOR_DEFAULT The default option for setSystemBarsBehavior(int): Window would like to remain interactive when hiding navigation bars by calling hide(int) orWindowInsetsAnimationController.setInsetsAndAlpha(Insets, float, float). |
int | BEHAVIOR_SHOW_BARS_BY_SWIPE This constant was deprecated in API level 31. Use BEHAVIOR_DEFAULT instead. |
int | BEHAVIOR_SHOW_BARS_BY_TOUCH This constant was deprecated in API level 31. This is not supported on Android Build.VERSION_CODES.S and later. UseBEHAVIOR_DEFAULT or BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE instead. |
int | BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE Option for setSystemBarsBehavior(int): Window would like to remain interactive when hiding navigation bars by calling hide(int) orWindowInsetsAnimationController.setInsetsAndAlpha(Insets, float, float). |
Public methods | |
---|---|
abstract void | addOnControllableInsetsChangedListener(WindowInsetsController.OnControllableInsetsChangedListener listener) Adds a OnControllableInsetsChangedListener to the window insets controller. |
abstract void | controlWindowInsetsAnimation(int types, long durationMillis, Interpolator interpolator, CancellationSignal cancellationSignal, WindowInsetsAnimationControlListener listener) Lets the application control window inset animations in a frame-by-frame manner by modifying the position of the windows in the system causing insets directly. |
abstract int | getSystemBarsAppearance() Retrieves the requested appearance of system bars. |
abstract int | getSystemBarsBehavior() Retrieves the requested behavior of system bars. |
abstract void | hide(int types) Makes a set of windows causing insets disappear. |
abstract void | removeOnControllableInsetsChangedListener(WindowInsetsController.OnControllableInsetsChangedListener listener) Removes a OnControllableInsetsChangedListener from the window insets controller. |
abstract void | setSystemBarsAppearance(int appearance, int mask) Controls the appearance of system bars. |
abstract void | setSystemBarsBehavior(int behavior) Controls the behavior of system bars. |
abstract void | show(int types) Makes a set of windows that cause insets appear on screen. |
Constants
APPEARANCE_LIGHT_NAVIGATION_BARS
public static final int APPEARANCE_LIGHT_NAVIGATION_BARS
Changes the foreground color for light navigation bars so that the items on the bar can be read clearly.
Constant Value: 16 (0x00000010)
APPEARANCE_LIGHT_STATUS_BARS
public static final int APPEARANCE_LIGHT_STATUS_BARS
Changes the foreground color for light status bars so that the items on the bar can be read clearly.
Constant Value: 8 (0x00000008)
APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND
public static final int APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND
Makes the caption bar transparent.
Constant Value: 128 (0x00000080)
BEHAVIOR_DEFAULT
public static final int BEHAVIOR_DEFAULT
The default option for [setSystemBarsBehavior(int)](/reference/android/view/WindowInsetsController#setSystemBarsBehavior%28int%29)
: Window would like to remain interactive when hiding navigation bars by calling [hide(int)](/reference/android/view/WindowInsetsController#hide%28int%29)
or[WindowInsetsAnimationController.setInsetsAndAlpha(Insets, float, float)](/reference/android/view/WindowInsetsAnimationController#setInsetsAndAlpha%28android.graphics.Insets,%20float,%20float%29)
.
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.
When the gesture navigation is enabled, the system gestures can be triggered regardless the visibility of system bars.
Constant Value: 1 (0x00000001)
BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
public static final int BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
Option for [setSystemBarsBehavior(int)](/reference/android/view/WindowInsetsController#setSystemBarsBehavior%28int%29)
: Window would like to remain interactive when hiding navigation bars by calling [hide(int)](/reference/android/view/WindowInsetsController#hide%28int%29)
or[WindowInsetsAnimationController.setInsetsAndAlpha(Insets, float, float)](/reference/android/view/WindowInsetsAnimationController#setInsetsAndAlpha%28android.graphics.Insets,%20float,%20float%29)
.
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\u2019s content, may have some degree of transparency, and will automatically hide after a short timeout.
Constant Value: 2 (0x00000002)
Public methods
controlWindowInsetsAnimation
public abstract void controlWindowInsetsAnimation (int types, long durationMillis, Interpolator interpolator, CancellationSignal cancellationSignal, WindowInsetsAnimationControlListener listener)
Lets the application control window inset animations in a frame-by-frame manner by modifying the position of the windows in the system causing insets directly.
Parameters | |
---|---|
types | int: The WindowInsets.Types the application has requested to control. Value is either 0 or a combination of android.view.WindowInsets.Type.STATUS_BARS, android.view.WindowInsets.Type.NAVIGATION_BARS, android.view.WindowInsets.Type.CAPTION_BAR, android.view.WindowInsets.Type.IME, android.view.WindowInsets.Type.WINDOW_DECOR, android.view.WindowInsets.Type.SYSTEM_GESTURES, android.view.WindowInsets.Type.MANDATORY_SYSTEM_GESTURES, android.view.WindowInsets.Type.TAPPABLE_ELEMENT, android.view.WindowInsets.Type.DISPLAY_CUTOUT, and android.view.WindowInsets.Type.SYSTEM_OVERLAYS |
durationMillis | long: Duration of animation inTimeUnit.MILLISECONDS, or -1 if the animation doesn't have a predetermined duration. This value will be passed to WindowInsetsAnimation.getDurationMillis() |
interpolator | Interpolator: The interpolator used for this animation, or null if this animation doesn't follow an interpolation curve. This value will be passed to WindowInsetsAnimation.getInterpolator() and used to calculate WindowInsetsAnimation.getInterpolatedFraction(). |
cancellationSignal | CancellationSignal: A cancellation signal that the caller can use to cancel the request to obtain control, or once they have control, to cancel the control. This value may be null. |
listener | WindowInsetsAnimationControlListener: The WindowInsetsAnimationControlListener that gets called when the windows are ready to be controlled, among other callbacks. This value cannot be null. |
See also:
[WindowInsetsAnimation.getFraction()](/reference/android/view/WindowInsetsAnimation#getFraction%28%29)
[WindowInsetsAnimation.getInterpolatedFraction()](/reference/android/view/WindowInsetsAnimation#getInterpolatedFraction%28%29)
[WindowInsetsAnimation.getInterpolator()](/reference/android/view/WindowInsetsAnimation#getInterpolator%28%29)
[WindowInsetsAnimation.getDurationMillis()](/reference/android/view/WindowInsetsAnimation#getDurationMillis%28%29)
getSystemBarsAppearance
public abstract int getSystemBarsAppearance ()
Retrieves the requested appearance of system bars.
Returns | |
---|---|
int | The requested bitmask of system bar appearance controlled by this window. Value is either 0 or a combination of android.view.WindowInsetsController.APPEARANCE_OPAQUE_STATUS_BARS, android.view.WindowInsetsController.APPEARANCE_OPAQUE_NAVIGATION_BARS, android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS, APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_NAVIGATION_BARS, android.view.WindowInsetsController.APPEARANCE_SEMI_TRANSPARENT_STATUS_BARS, android.view.WindowInsetsController.APPEARANCE_SEMI_TRANSPARENT_NAVIGATION_BARS, APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND, APPEARANCE_LIGHT_CAPTION_BARS, and android.view.WindowInsetsController.APPEARANCE_FORCE_LIGHT_NAVIGATION_BARS |
See also:
[setSystemBarsAppearance(int, int)](/reference/android/view/WindowInsetsController#setSystemBarsAppearance%28int,%20int%29)
[R.attr.windowLightStatusBar](/reference/android/R.attr#windowLightStatusBar)
[R.attr.windowLightNavigationBar](/reference/android/R.attr#windowLightNavigationBar)
hide
public abstract void hide (int types)
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](/reference/android/view/View#onApplyWindowInsets%28android.view.WindowInsets%29)
and checking visibility with [WindowInsets.isVisible](/reference/android/view/WindowInsets#isVisible%28int%29)
.
Parameters | |
---|---|
types | int: A bitmask of WindowInsets.Type specifying what windows the app would like to make disappear. Value is either 0 or a combination of android.view.WindowInsets.Type.STATUS_BARS, android.view.WindowInsets.Type.NAVIGATION_BARS, android.view.WindowInsets.Type.CAPTION_BAR, android.view.WindowInsets.Type.IME, android.view.WindowInsets.Type.WINDOW_DECOR, android.view.WindowInsets.Type.SYSTEM_GESTURES, android.view.WindowInsets.Type.MANDATORY_SYSTEM_GESTURES, android.view.WindowInsets.Type.TAPPABLE_ELEMENT, android.view.WindowInsets.Type.DISPLAY_CUTOUT, and android.view.WindowInsets.Type.SYSTEM_OVERLAYS |
setSystemBarsAppearance
public abstract void setSystemBarsAppearance (int appearance, int mask)
Controls the appearance of system bars.
For example, the following statement adds [APPEARANCE_LIGHT_STATUS_BARS](/reference/android/view/WindowInsetsController#APPEARANCE%5FLIGHT%5FSTATUS%5FBARS)
:
setSystemBarsAppearance(APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_STATUS_BARS)
And the following statement clears it:
setSystemBarsAppearance(0, APPEARANCE_LIGHT_STATUS_BARS)
Parameters | |
---|---|
appearance | int: Bitmask of appearance flags. Value is either 0 or a combination of android.view.WindowInsetsController.APPEARANCE_OPAQUE_STATUS_BARS, android.view.WindowInsetsController.APPEARANCE_OPAQUE_NAVIGATION_BARS, android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS, APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_NAVIGATION_BARS, android.view.WindowInsetsController.APPEARANCE_SEMI_TRANSPARENT_STATUS_BARS, android.view.WindowInsetsController.APPEARANCE_SEMI_TRANSPARENT_NAVIGATION_BARS, APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND, APPEARANCE_LIGHT_CAPTION_BARS, and android.view.WindowInsetsController.APPEARANCE_FORCE_LIGHT_NAVIGATION_BARS |
mask | int: Specifies which flags of appearance should be changed. Value is either 0 or a combination of android.view.WindowInsetsController.APPEARANCE_OPAQUE_STATUS_BARS, android.view.WindowInsetsController.APPEARANCE_OPAQUE_NAVIGATION_BARS, android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS, APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_NAVIGATION_BARS, android.view.WindowInsetsController.APPEARANCE_SEMI_TRANSPARENT_STATUS_BARS, android.view.WindowInsetsController.APPEARANCE_SEMI_TRANSPARENT_NAVIGATION_BARS, APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND, APPEARANCE_LIGHT_CAPTION_BARS, and android.view.WindowInsetsController.APPEARANCE_FORCE_LIGHT_NAVIGATION_BARS |
setSystemBarsBehavior
public abstract void setSystemBarsBehavior (int behavior)
Controls the behavior of system bars.
Parameters | |
---|---|
behavior | int: Determines how the bars behave when being hidden by the application. Value is BEHAVIOR_DEFAULT, or BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE |
show
public abstract void show (int types)
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](/reference/android/view/View#onApplyWindowInsets%28android.view.WindowInsets%29)
and checking visibility with [WindowInsets.isVisible](/reference/android/view/WindowInsets#isVisible%28int%29)
.
Parameters | |
---|---|
types | int: A bitmask of WindowInsets.Type specifying what windows the app would like to make appear on screen. Value is either 0 or a combination of android.view.WindowInsets.Type.STATUS_BARS, android.view.WindowInsets.Type.NAVIGATION_BARS, android.view.WindowInsets.Type.CAPTION_BAR, android.view.WindowInsets.Type.IME, android.view.WindowInsets.Type.WINDOW_DECOR, android.view.WindowInsets.Type.SYSTEM_GESTURES, android.view.WindowInsets.Type.MANDATORY_SYSTEM_GESTURES, android.view.WindowInsets.Type.TAPPABLE_ELEMENT, android.view.WindowInsets.Type.DISPLAY_CUTOUT, and android.view.WindowInsets.Type.SYSTEM_OVERLAYS |