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.
class Builder
A builder class for creating instances of |
class ConsumeOptions |
static val CONSUME_ALL: Int
|
|
static val CONSUME_AUTO: Int
Any specified sides are consumed. This selectively consumes any sides which are set via |
|
static val CONSUME_NONE: Int
No consumption happens. This is the default value. |
fun applyInsetsToView(view: View, insets: WindowInsetsCompat, initialState: ViewState): Unit
A convenience function which applies insets to a view. |
|
static fun builder(): Insetter.Builder!
Returns a instance of |
|
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'. |