I have to make layout, where top of the layout should be drawn under SystemBars
. (min API level for this app is 22)
I set these flags to achieve that. In other activities I can draw whole fragment with views under SystemBars
, but here I cant do it.
I used this code to allow layout to be drawn under SystemBars
window.apply {
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
statusBarColor = resources.getColor(android.R.color.transparent)
navigationBarColor = resources.getColor(android.R.color.transparent)
setBackgroundDrawable(background)
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
This is result in app:
I need to draw that grey area under system bar.
Update:
@Redman solution worked only partially.
Now I can draw under StatusBar
but also I can draw under software buttons (navigationButtons
) as you can see at screen below. Is there any way how to allow layout to be drawn under SystemBars
but do not allow it under navigationButtons
? Because that code what I've posted works for different fragments in app. But in other fragments I don't have ImageView
as a part of ToolBar
. If you have just ToolBar
with for example 2-color gradient background and some backButton
+ SearchView
, it is working fine. But as I add ImageView
, ImageView
will not "slide" under top SystemBar(aka StatusBar)
. Even in image above you can clearly see that green color (it's ToolBar background drawn under StatusBar
). But ImageView
is not allowed to be drawn under that bar.
The only way how to achieve that was with that special line of code
window.apply {
setFlags( WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
}
but this line also allowed to draw layout content under NavigationButtons
(which is an issue).