다음을 통해 공유


View.FitSystemWindows(Rect) Method

Definition

Caution

deprecated

Called by the view hierarchy when the content insets for a window have changed, to allow it to adjust its content to fit within those windows.

[Android.Runtime.Register("fitSystemWindows", "(Landroid/graphics/Rect;)Z", "GetFitSystemWindows_Landroid_graphics_Rect_Handler")]
[System.Obsolete("deprecated")]
protected virtual bool FitSystemWindows (Android.Graphics.Rect? insets);
[<Android.Runtime.Register("fitSystemWindows", "(Landroid/graphics/Rect;)Z", "GetFitSystemWindows_Landroid_graphics_Rect_Handler")>]
[<System.Obsolete("deprecated")>]
abstract member FitSystemWindows : Android.Graphics.Rect -> bool
override this.FitSystemWindows : Android.Graphics.Rect -> bool

Parameters

insets
Rect

Current content insets of the window. Prior to android.os.Build.VERSION_CODES#JELLY_BEAN you must not modify the insets or else you and Android will be unhappy.

Returns

true if this view applied the insets and it should not continue propagating further down the hierarchy, false otherwise.

Attributes

Remarks

Called by the view hierarchy when the content insets for a window have changed, to allow it to adjust its content to fit within those windows. The content insets tell you the space that the status bar, input method, and other system windows infringe on the application's window.

You do not normally need to deal with this function, since the default window decoration given to applications takes care of applying it to the content of the window. If you use #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION this will not be the case, and your content can be placed under those system elements. You can then use this method within your view hierarchy if you have parts of your UI which you would like to ensure are not being covered.

The default implementation of this method simply applies the content insets to the view's padding, consuming that content (modifying the insets to be 0), and returning true. This behavior is off by default, but can be enabled through #setFitsSystemWindows(boolean).

This function's traversal down the hierarchy is depth-first. The same content insets object is propagated down the hierarchy, so any changes made to it will be seen by all following views (including potentially ones above in the hierarchy since this is a depth-first traversal). The first view that returns true will abort the entire traversal.

The default implementation works well for a situation where it is used with a container that covers the entire window, allowing it to apply the appropriate insets to its content on all edges. If you need a more complicated layout (such as two different views fitting system windows, one on the top of the window, and one on the bottom), you can override the method and handle the insets however you would like. Note that the insets provided by the framework are always relative to the far edges of the window, not accounting for the location of the called view within that window. (In fact when this method is called you do not yet know where the layout will place the view, as it is done before layout happens.)

Note: unlike many View methods, there is no dispatch phase to this call. If you are overriding it in a ViewGroup and want to allow the call to continue to your children, you must be sure to call the super implementation.

Here is a sample layout that makes use of fitting system windows to have controls for a video view placed inside of the window decorations that it hides and shows. This can be used with code like the second sample (video player) shown in #setSystemUiVisibility(int).

{

This member is deprecated. As of API 20 use #dispatchApplyWindowInsets(WindowInsets) to apply insets to views. Views should override #onApplyWindowInsets(WindowInsets) or use #setOnApplyWindowInsetsListener(android.view.View.OnApplyWindowInsetsListener) to implement handling their own insets.

Java documentation for android.view.View.fitSystemWindows(android.graphics.Rect).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also