You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classYourActivity : AppCompatActivity() {
overridefunonCreate(savedInstanceState:Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
val root = setContentView(R.layout.activity_your, insetsProvider =InsetsProviderImpl())
val binding =ActivityYourBinding.bind(root) // if needed, or root.findViewById()
}
}
Step 3 alternative 2
// if you need the Activity to be an insets provider to have access to it not only from UIclassYourActivity : AppCompatActivity(), InsetsProvider by InsetsProviderImpl() {
overridefunonCreate(savedInstanceState:Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
val root = setContentView(R.layout.activity_your, insetsProvider =this)
val binding =ActivityYourBinding.bind(root) // if needed, or root.findViewById()
}
}
How to use
importandroidx.core.graphics.Insetsimportlib.atomofiron.insets.ExtendedWindowInsetsimportlib.atomofiron.insets.TypeSet// apply bottom ime insets as padding
view1.insetsPadding(Type.ime, bottom =true)
// apply insets as padding at the top and as margin horizontally
view2.insetsMix { // Type.barsWithCutout by default
margin(horizontal).padding(top)
}
insetsProvider.setInsetsModifier { _, windowInsets ->
windowInsets.builder()
// modify insets
.build()
}
// define your oun custom inset typesobject ExtType : ExtendedWindowInsets.Type() {
val togglePanel = define("togglePanel")
val verticalPanels = define("verticalPanels")
val fab = define("fab")
val general = define("general")
inlineoperatorfuninvoke(block:ExtType.() ->TypeSet): TypeSet=ExtType.block()
}
// associate your custom type with ExtendedWindowInsetsoperatorfun ExtendedWindowInsets.invoke(block:ExtType.() ->TypeSet): Insets= get(ExtType.block())
// provide custom insets
fab.insetsSource { view ->val insets =Insets.of(view.visibleLeftWidth, 0, view.visibleRightWidth, view.visibleBottomHeight)
InsetsSource.submit(ExtType.fab, insets)
}