Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • This is the most accurate answer today Commented Feb 5, 2018 at 21:46
  • for me this only fires once, If I have fragments via bottom nav. If I replace the fragment again, this listener doesnt get called, is there a compat getter aswell? Commented Mar 11, 2018 at 2:51
  • 154
    And yet this API is horrible, because the number of WTF/Gotchas behind the scenes is huge. You’d think that you can do it with any view, but no, you need to override certain things and ensure YOU pass the insets to your children (??) because SOME ViewGroups will (material design) and ALL OTHERS won’t (linear layout? ConstraintLayout? hello?). Instead of the system having a Window.getStatusBarSize()… we have to SUBSCRIBE TO A FREAKING LISTENER… go home Android, you’re drunk. Just hardcode the size until Google wakes up, we’re in 2018. I hope Chris Banes sees this one day… Commented Jun 19, 2018 at 20:49
  • 1
    You need to call view.onApplyWindowInsets, because otherwise the view's own method won't be called. Moreover, your code is syntactically wrong (misplaced brace, return statement from closure). Commented Mar 30, 2021 at 5:46
  • 5
    insets.systemWindowInsetTop is deprecated now. So the most actual way now how to get statusbar insets today: val statusbarInsets = insets.getInsets(WindowInsetsCompat.Type.statusBars()) and then statusbarInsets.top. Read more about how to handle overlaps using insets when implementing edge-to-edge developer.android.com/training/gestures/… Commented Aug 8, 2022 at 14:40