Last active
April 5, 2022 05:59
-
-
Save AndroidPoet/079984f10ab32b5b0aab31c865ba18e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Add these lines inside your MainActivity. | |
if (Build.VERSION.SDK_INT >= 30) { | |
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, windowInsets -> | |
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) | |
// Apply the insets as a margin to the view. Here the system is setting | |
// only the bottom, left, and right dimensions, but apply whichever insets are | |
// appropriate to your layout. You can also update the view padding | |
// if that's more appropriate. | |
view.layoutParams = (view.layoutParams as FrameLayout.LayoutParams).apply { | |
leftMargin = insets.left | |
bottomMargin = insets.bottom | |
rightMargin = insets.right | |
} | |
// Return CONSUMED if you don't want want the window insets to keep being | |
// passed down to descendant views. | |
WindowInsetsCompat.CONSUMED | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment