BECOMING A MASTER WINDOW FITTER
myView.setOnApplyWindowInsetsListener { view, insets ->
// TODO handle insets
return insets.consumeSystemWindowInsets()
}
Slide 120
Slide 120 text
BECOMING A MASTER WINDOW FITTER
ViewCompat.setOnApplyWindowInsetsListener(view) { view, insets ->
// TODO handle insets
return insets.consumeSystemWindowInsets()
}
Slide 121
Slide 121 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 122
Slide 122 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 123
Slide 123 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 166
Slide 166 text
BECOMING A MASTER WINDOW FITTER
Avoid translucent system bars
#80000000
#80000000
Slide 167
Slide 167 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 168
Slide 168 text
BECOMING A MASTER WINDOW FITTER
Repeat once per week
I will never store or retrieve the status bar size from
resources ever again