BECOMING A MASTER WINDOW FITTER
myView.setOnApplyWindowInsetsListener { view, insets ->
// TODO handle insets
return insets.consumeSystemWindowInsets()
}
Slide 117
Slide 117 text
BECOMING A MASTER WINDOW FITTER
ViewCompat.setOnApplyWindowInsetsListener(view) { view, insets ->
// TODO handle insets
return insets.consumeSystemWindowInsets()
}
Slide 118
Slide 118 text
BECOMING A MASTER WINDOW FITTER
class CustomLayout : LinearLayout {
// yadda yadda
override fun onApplyWindowInsets(
insets: WindowInsets): WindowInsets {
// TODO handle the insets
return insets.consumeSystemWindowInsets()
}
}
Slide 119
Slide 119 text
BECOMING A MASTER WINDOW FITTER
class CustomLayout : LinearLayout {
// yadda yadda
override fun onApplyWindowInsets(
insets: WindowInsets): WindowInsets {
// TODO handle the insets
return insets.consumeSystemWindowInsets()
}
}
Slide 120
Slide 120 text
BECOMING A MASTER WINDOW FITTER
WindowInsets will be passed down until
it has been consumed
BECOMING A MASTER WINDOW FITTER
If you’re using DrawerLayout or CoordinatorLayout
Use android:fitSystemWindows="true" on
direct children which you want to be displayed behind
the system bars
Slide 135
Slide 135 text
BECOMING A MASTER WINDOW FITTER
Avoid translucent system bars
#80000000
#80000000
Slide 136
Slide 136 text
BECOMING A MASTER WINDOW FITTER
If you need to get access to the status bar size
myView.setOnApplyWindowInsetsListener { view, insets ->
val statusBarSize = insets.systemWindowInsetTop
return insets
}
Slide 137
Slide 137 text
BECOMING A MASTER WINDOW FITTER
Repeat once per week
I will never store or retrieve the status bar size from
resources ever again