Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding WindowInsets - Android Worldwide

Understanding WindowInsets - Android Worldwide

Subhrajyoti Sen

July 26, 2021
Tweet

More Decks by Subhrajyoti Sen

Other Decks in Technology

Transcript

  1. Insets - Types • • • • • Status Bars

    Navigation Bars Caption Bar IME System Gestures
  2. Insets - Types • • • • • • Status

    Bars Navigation Bars Caption Bar IME System Gestures Display Cutouts
  3. Fetching WindowInsets binding.root.setOnApplyWindowInsetsListener { _, insets -> val navigationBarHeight =

    insets.getInsets( WindowInsets.Type.navigationBars() ).bottom (binding.root.layoutParams as? ViewGroup.MarginLayoutParams)?. bottomMargin = navigationBarHeight }
  4. Padding for Notch (Display Cutout) binding.root.setOnApplyWindowInsetsListener { _, insets ->

    notchHeight = WindowInsetsCompat.toWindowInsetsCompat(insets) .getInsets(WindowInsetsCompat.Type.displayCutout()) .top }
  5. Padding for Notch (Display Cutout) binding.root.setOnApplyWindowInsetsListener { _, insets ->

    notchHeight = WindowInsetsCompat.toWindowInsetsCompat(insets) .getInsets(WindowInsetsCompat.Type.displayCutout()) .top }
  6. Padding for Notch (Display Cutout) binding.root.setOnApplyWindowInsetsListener { _, insets ->

    notchHeight = WindowInsetsCompat.toWindowInsetsCompat(insets) .getInsets(WindowInsetsCompat.Type.displayCutout()) .top }
  7. Padding for Notch (Display Cutout) binding.root.setOnApplyWindowInsetsListener { _, insets ->

    notchHeight = WindowInsetsCompat.toWindowInsetsCompat(insets) .getInsets(WindowInsetsCompat.Type.displayCutout()) .top binding.toolbar.updatePadding(top= notchHeight) insets }
  8. Status Bar Appearance (Earlier) val decor = window.decorView decor.systemUiVisibility =

    decor.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR Light status bar
  9. Status Bar Appearance (Earlier) val decor = window.decorView decor.systemUiVisibility =

    decor.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() Dark status bar
  10. Status Bar Appearance (Earlier) val decor = window.decorView decor.systemUiVisibility =

    decor.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() On API 30+
  11. Check keyboard visibility binding.root.setOnApplyWindowInsetsListener { _, insets -> val visible

    = WindowInsetsCompat.toWindowInsetsCompat(insets) .isVisible(WindowInsetsCompat.Type.ime()) }