In Android, what are window insets?

They are some kind of colored margin (used in Android Wear).

They are used to create a padding from the main content to the actual border:

There are a few examples here.


This is an image with 2 insets: Circle/Squared.

enter image description here


They can also be used in other views to handle especial rendering requirements, like in a ScrollView: where to put the actual scroll can be defined with an insideInset as mentioned in this question.

<ScrollView
    android:id="@+id/view2"
    android:layout_width="100dip"
    android:layout_height="120dip"
    android:padding="8dip"
    android:scrollbarStyle="insideInset"
    android:background="@android:color/white"
    android:overScrollMode="never">

Insets are areas of your view that you should not put elements, like behind the status bar or navigation bar. Think of them like paddings for the window.

If you want to draw behind them, like putting an image to the top that should be behind a translucent status bar, you will need to consume the window insets. In some views this is as easy as putting android:fitsSystemWindows=true, but in others you will have to override the onApplyWindowInsets method.

Usually the window insets for phones are the size of the height of the status bar as the top, the size of the navigation bar as the bottom and 0 as left and right. But It can be different, like in watches or phones with physical buttons.

Tags:

Android

Window