Google is committed to advancing racial equity for Black communities. See how.
Added in API level 30

WindowMetrics

class WindowMetrics
kotlin.Any
   ↳ android.view.WindowMetrics

Metrics about a Window, consisting of the bounds and WindowInsets.

This is usually obtained from WindowManager#getCurrentWindowMetrics() and WindowManager#getMaximumWindowMetrics().

Summary

Public constructors
<init>(bounds: Rect, windowInsets: WindowInsets)

Public methods
Rect

Returns the bounds of the area associated with this window or visual context.

WindowInsets

Returns the WindowInsets of the area associated with this window or visual context.

Public constructors

<init>

Added in API level 30
WindowMetrics(
    bounds: Rect,
    windowInsets: WindowInsets)
Parameters
bounds Rect: This value cannot be null.
windowInsets WindowInsets: This value cannot be null.

Public methods

getBounds

Added in API level 30
fun getBounds(): Rect

Returns the bounds of the area associated with this window or visual context.

Note that the size of the reported bounds can have different size than Display#getSize(Point). This method reports the window size including all system bar areas, while Display#getSize(Point) reports the area excluding navigation bars and display cutout areas. The value reported by Display#getSize(Point) can be obtained by using:

final WindowMetrics metrics = windowManager.getCurrentWindowMetrics();
  // Gets all excluding insets
  final WindowInsets windowInsets = metrics.getWindowInsets();
  Insets insets = windowInsets.getInsetsIgnoreVisibility(WindowInsets.Type.navigationBars()
          | WindowInsets.Type.displayCutout());
 
  int insetsWidth = insets.right + insets.left;
  int insetsHeight = insets.top + insets.bottom;
 
  // Legacy size that Display#getSize reports
  final Rect bounds = metrics.getBounds();
  final Size legacySize = new Size(bounds.width() - insetsWidth,
          bounds.height() - insetsHeight);
  

Return
Rect window bounds in pixels. This value cannot be null.

getWindowInsets

Added in API level 30
fun getWindowInsets(): WindowInsets

Returns the WindowInsets of the area associated with this window or visual context.

Return
WindowInsets the WindowInsets of the visual area. This value cannot be null.