WindowInsetsControllerCompat
public final class 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
Nested types |
|---|
public interface WindowInsetsControllerCompat.OnControllableInsetsChangedListenerListener to be notified when the set of controllable |
Constants |
|
|---|---|
static final int |
BEHAVIOR_DEFAULT = 1The default option for |
static final int |
This field is deprecated. Use |
static final int |
This field is deprecated. This is not supported on Android |
static final int |
Option for |
Public constructors |
|---|
WindowInsetsControllerCompat(@NonNull Window window, @NonNull View view) |
Public methods |
|
|---|---|
void |
addOnControllableInsetsChangedListener(Adds a |
void |
controlWindowInsetsAnimation(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 using |
int |
Retrieves the requested behavior of system bars. |
void |
hide(int types)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. |
void |
removeOnControllableInsetsChangedListener(Removes a |
void |
setAppearanceLightNavigationBars(boolean isLight)If true, changes the foreground color of the navigation bars to light so that the items on the bar can be read clearly. |
void |
setAppearanceLightStatusBars(boolean isLight)If true, changes the foreground color of the status bars to light so that the items on the bar can be read clearly. |
void |
setSystemBarsBehavior(int behavior)Controls the behavior of system bars. |
void |
show(int types)Makes a set of windows that cause insets appear on screen. |
static @NonNull WindowInsetsControllerCompat |
@RequiresApi(value = 30)This method is deprecated. Use |
Constants
BEHAVIOR_DEFAULT
public static final int BEHAVIOR_DEFAULT = 1
The default option for setSystemBarsBehavior: Window would like to remain interactive when hiding navigation bars by calling hide or setInsetsAndAlpha.
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.
public static final int BEHAVIOR_SHOW_BARS_BY_SWIPE = 1
Option for setSystemBarsBehavior: Window would like to remain interactive when hiding navigation bars by calling hide or setInsetsAndAlpha.
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.
public static final int BEHAVIOR_SHOW_BARS_BY_TOUCH = 0
Option for setSystemBarsBehavior. System bars will be forcibly shown on any user interaction on the corresponding display if navigation bars are hidden by hide or setInsetsAndAlpha.
BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
public static final int BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE = 2
Option for setSystemBarsBehavior: Window would like to remain interactive when hiding navigation bars by calling hide or setInsetsAndAlpha.
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.
Public constructors
Public methods
addOnControllableInsetsChangedListener
public void addOnControllableInsetsChangedListener(
@NonNull WindowInsetsControllerCompat.OnControllableInsetsChangedListener listener
)
Adds a WindowInsetsController.OnControllableInsetsChangedListener to the window insets controller.
| Parameters | |
|---|---|
@NonNull WindowInsetsControllerCompat.OnControllableInsetsChangedListener listener |
The listener to add. |
controlWindowInsetsAnimation
public void controlWindowInsetsAnimation(
int types,
long durationMillis,
@Nullable Interpolator interpolator,
@Nullable CancellationSignal cancellationSignal,
@NonNull WindowInsetsAnimationControlListenerCompat 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 using setInsetsAndAlpha in the controller provided by the given listener.
This method only works on API >= 30 since there is no way to control the window in the system on prior APIs.
| Parameters | |
|---|---|
int types |
The |
long durationMillis |
Duration of animation in |
@Nullable Interpolator interpolator |
The interpolator used for this animation, or |
@Nullable 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. |
@NonNull WindowInsetsAnimationControlListenerCompat listener |
The |
getSystemBarsBehavior
public int getSystemBarsBehavior()
Retrieves the requested behavior of system bars.
| Returns | |
|---|---|
int |
the system bar behavior controlled by this window. |
| See also | |
|---|---|
setSystemBarsBehavior |
hide
public 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 onApplyWindowInsets and checking visibility with isVisible.
| Parameters | |
|---|---|
int types |
A bitmask of |
isAppearanceLightNavigationBars
public boolean isAppearanceLightNavigationBars()
Checks if the foreground of the navigation bar is set to light.
This method always returns false on API <26.
If this value is being set in the theme (via windowLightNavigationBar), then the correct value will only be returned once attached to the window.
Once this method is called, modifying `systemUiVisibility` directly to change the appearance is undefined behavior.
| Returns | |
|---|---|
boolean |
true if the foreground is light |
| See also | |
|---|---|
setAppearanceLightNavigationBars |
isAppearanceLightStatusBars
public boolean isAppearanceLightStatusBars()
Checks if the foreground of the status bar is set to light.
This method always returns false on API <23.
If this value is being set in the theme (via windowLightStatusBar), then the correct value will only be returned once attached to the window.
Once this method is called, modifying `systemUiVisibility` directly to change the appearance is undefined behavior.
| Returns | |
|---|---|
boolean |
true if the foreground is light |
| See also | |
|---|---|
setAppearanceLightStatusBars |
removeOnControllableInsetsChangedListener
public void removeOnControllableInsetsChangedListener(
@NonNull WindowInsetsControllerCompat.OnControllableInsetsChangedListener listener
)
Removes a WindowInsetsController.OnControllableInsetsChangedListener from the window insets controller.
| Parameters | |
|---|---|
@NonNull WindowInsetsControllerCompat.OnControllableInsetsChangedListener listener |
The listener to remove. |
setAppearanceLightNavigationBars
public void setAppearanceLightNavigationBars(boolean isLight)
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.
Once this method is called, modifying `systemUiVisibility` directly to change the appearance is undefined behavior.
| See also | |
|---|---|
isAppearanceLightNavigationBars |
setAppearanceLightStatusBars
public void setAppearanceLightStatusBars(boolean isLight)
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.
Once this method is called, modifying `systemUiVisibility` directly to change the appearance is undefined behavior.
| See also | |
|---|---|
isAppearanceLightStatusBars |
setSystemBarsBehavior
public void setSystemBarsBehavior(int behavior)
Controls the behavior of system bars.
| Parameters | |
|---|---|
int behavior |
Determines how the bars behave when being hidden by the application. |
| See also | |
|---|---|
getSystemBarsBehavior |
show
public 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 onApplyWindowInsets and checking visibility with isVisible.
| Parameters | |
|---|---|
int types |
A bitmask of |
@RequiresApi(value = 30)
public static @NonNull WindowInsetsControllerCompattoWindowInsetsControllerCompat(
@NonNull WindowInsetsController insetsController
)
Wrap a WindowInsetsController into a WindowInsetsControllerCompat for compatibility purpose.
| Parameters | |
|---|---|
@NonNull WindowInsetsController insetsController |
The |
| Returns | |
|---|---|
@NonNull WindowInsetsControllerCompat |
The provided |