I am building an application and there is a profile fragment which shows a profile background image and some other elements. Like the screenshot below:
My quest
Based on @Akshay answer this is my solution:
In the xml file add android:fitsSystemWindows="true" to:
In the Activity add @Akshay answer but edit it as follow (written in Kotlin):
ViewCompat.setOnApplyWindowInsetsListener(appBarLayout) { _, insets ->
// Instead of
// toolbar.setPadding(0, insets.systemWindowInsetTop, 0, 0)
(toolbar.layoutParams as ViewGroup.MarginLayoutParams).topMargin = insets.systemWindowInsetTop
insets.consumeSystemWindowInsets()
}
Now the toolbar will have the proper height as well.