A Data Binding extension library, providing Data Binding-specific functionality. This primarily contains binding adapters, which allow access to the helper functions from your layouts. Currently the attributes provided are:
Applying system window insets
The following attributes are useful in being able to apply the system window insets insets, to specific dimensions to views.
app:paddingLeftSystemWindowInsets
: to apply the left dimension to the view'spaddingLeft
.app:paddingTopSystemWindowInsets
: to apply the top dimension to the view'spaddingTop
.app:paddingRightSystemWindowInsets
: to apply the right dimension to the view'spaddingRight
.app:paddingBottomSystemWindowInsets
: to apply the bottom dimension to the view'spaddingBottom
.app:layout_marginLeftSystemWindowInsets
: to apply the left dimension to the view'slayout_marginLeft
.app:layout_marginTopSystemWindowInsets
: to apply the top dimension to the view'slayout_marginTop
.app:layout_marginRightSystemWindowInsets
: to apply the right dimension to the view'slayout_marginRight
.app:layout_marginBottomSystemWindowInsets
: to apply the bottom dimension to the view'slayout_marginBottom
.
Applying system gesture insets
The following attributes are useful in being able to apply the system gesture insets insets, to specific dimensions to views.
app:paddingLeftSystemGestureInsets
: to apply the left dimension to the view'spaddingLeft
.app:paddingTopSystemGestureInsets
: to apply the top dimension to the view'spaddingTop
.app:paddingRightSystemGestureInsets
: to apply the right dimension to the view'spaddingRight
.app:paddingBottomSystemGestureInsets
: to apply the bottom dimension to the view'spaddingBottom
.app:layout_marginLeftSystemGestureInsets
: to apply the left dimension to the view'slayout_marginLeft
.app:layout_marginTopSystemGestureInsets
: to apply the top dimension to the view'slayout_marginTop
.app:layout_marginRightSystemGestureInsets
: to apply the right dimension to the view'slayout_marginRight
.app:layout_marginBottomSystemGestureInsets
: to apply the bottom dimension to the view'slayout_marginBottom
.
Each of the attributes takes a boolean
value of whether the attribute functionality is enabled or not,
like so:
<ImageView
app:paddingBottomSystemWindowInsets="@{true}"
app:paddingLeftSystemWindowInsets="@{true}" />
You can use any non-exclusive combination of insets and application type, such as the following which uses the bottom system window inset for padding, and the left gesture inset for margin:
<ImageView
app:paddingBottomSystemWindowInsets="@{true}"
app:layout_marginLeftSystemGestureInsets="@{true}" />
You can safely set any padding or margins on the view, and the values will be maintained.
For example here we're using a padding of 24dp
, and also applying the
system window insets left and bottom using padding:
<ImageView
app:paddingLeftSystemWindowInsets="@{true}"
app:paddingBottomSystemWindowInsets="@{true}"
android:padding="24dp" />
If the bottom system window insets is defined as 48dp
on the device, the final
applied padding for the view will be:
Dimension | Layout padding | System window insets | Final applied padding |
---|---|---|---|
Left | 24dp | 0dp | 24dp |
Top | 24dp | 0dp | 24dp (0 + 24) |
Right | 24dp | 0dp | 24dp |
Bottom | 24dp | 48dp | 72dp (24 + 48) |
The same behavior happens when using margin too.
There is currently just one edge-to-edge attribute:
app:layout_edgeToEdge
: Set this view's system-ui visibility with the flags required to be laid out 'edge-to-edge', or not.
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_edgeToEdge="@{true}">
<!-- Yadda yadda -->
</FrameLayout>
The behavior enabled through the widgets library is similar to that provided by the this library, but without the requirement of using data-binding. If you're already using data-binding I recommend using the dbx library and it's binding adapters, since they work with any view type.
However, if you do not use data-binding and do not wish to do so, the widgets library provides very similar functionality at the cost of having to migrate to the insetter widget types.