library / dev.chrisbanes.insetter / Insetter

Insetter

class Insetter

A helper class to make handling android.view.WindowInsets easier.

It includes a Builder for building easy-to-use OnApplyWindowInsetsListener instances:


  Insetter.builder()
      // This will apply the system window insets as padding to left, bottom and right of the view
      .applySystemWindowInsetsToPadding(Side.LEFT | Side.BOTTOM | Side.RIGHT)
      // This is a shortcut for view.setOnApplyWindowInsetsListener(builder.build())
      .applyToView(view);
  
Each inset type as on Android 10 (API level 29) is included, with variants for applying the inset as either padding or margin on the view.

You can also provide custom logic via the function. The listener type is slightly different to OnApplyWindowInsetsListener, in that it contains a third parameter to tell you what the initial view padding/margin state is.

By default the listener will not consume any insets which are passed to it. If you wish to consume the system window insets, you can use the function.

Types

Builder

class Builder

A builder class for creating instances of Insetter.

Functions

applyInsetsToView

fun applyInsetsToView(view: View, insets: WindowInsetsCompat, initialState: ViewState): Unit

A convenience function which applies insets to a view.

builder

static fun builder(): Insetter.Builder!

Returns a instance of Builder used for creating an instance of Insetter.

setEdgeToEdgeSystemUiFlags

static fun setEdgeToEdgeSystemUiFlags(view: View, enabled: Boolean): Unit

Set this view's system-ui visibility, with the flags required to be laid out 'edge-to-edge'.