Skip to content

Instantly share code, notes, and snippets.

@Ahmad-Hamwi
Created July 28, 2021 18:14
Show Gist options
  • Save Ahmad-Hamwi/10b9e9dec5845c43f0d5ebf8de8736a4 to your computer and use it in GitHub Desktop.
Save Ahmad-Hamwi/10b9e9dec5845c43f0d5ebf8de8736a4 to your computer and use it in GitHub Desktop.
A useful binding adapter that stretch the views boundaries to draw behind the system bar insets (aka going edge-to-edge)
/**
* example:
*
* <!--parent container (that's expanded to fullscreen)-->
* <androidx.constraintlayout.widget.ConstraintLayout
* android:layout_width="match_parent"
* android:layout_height="match_parent"
* ...
* app:setDecorFitSystemWindow="@{true}">
* ...
* ...
* ...
* </androidx.constraintlayout.widget.ConstraintLayout>
*/
@BindingAdapter("app:setDecorFitSystemWindow")
fun setDecorFitSystemWindow(view: View, apply: Boolean) {
if (!apply) return
if (view.context is Activity) {
WindowCompat.setDecorFitsSystemWindows((view.context as Activity).window, false)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment