I have an activity with a Navigation Drawer
and using ScrimInsetsFrameLayout
I was able to put the layout under the StatusBar
and everything worked perfectly.
Then I decided to replace the color for the Toolbar
and StatusBar
with a png
background for all the activity layout.
I run the app on the emulator (Nexus 5 with android 6.0) and the result was exactly what I wanted like you can see in Image #1 below, but when I tried on my device (Galaxy Note 3 with android 5.0) the layout inside ScrimInsetsFrameLayout went above the StatusBar
Image #2.
I can't understand what is wrong, can you help me?
Here are my values-v21
and my activity.xml
<style parent="Theme.AppCompat.Light.NoActionBar" name="AppTheme_Activities">
<item name="android:colorPrimary">@android:color/transparent</item>
<item name="android:colorPrimaryDark">@color/insetF</item>
<item name="android:navigationBarColor">@color/insetF</item>
<item name="android:colorAccent">@color/primary</item>
<item name="android:colorEdgeEffect">@color/primary</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">@color/insetF</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
<?xml version="1.0"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/drawer"
android:fitsSystemWindows="true"
android:background="@drawable/background"> <!--png image-->
<FrameLayout
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent">
<include layout="@layout/toolbar_activities" android:id="@+id/toolbar_layout"/>
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/content_frame">
</FrameLayout>
</FrameLayout>
<com.example.myapplication.ScrimInsetsFrameLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/linearLayout"
android:layout_width="304dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:insetForeground="#4000"
android:clickable="true"
android:background="#ffffff"> .....
</com.example.myapplication.ScrimInsetsFrameLayout>
</android.support.v4.widget.DrawerLayout>
add to your
onCreate()
ofActivity
Change
ScrimInsetsFrameLayout
'sandroid:fitsSystemWindows
property tofalse
Remove
android:fitsSystemWindows="true"
fromDrawerLayout
Add these styles into your
AppTheme_Activities
Theme (keeping your status desired color):This will to the state, that Toolbar gets under the StatusBar too, so you'll need to do this hack:
Make
Toolbar
's height ="wrap_content"
Set
Padding
for theToolbar
:That's should be it!
I've uploaded the source code of the test-application with Navigation Drawer below the status bar to my dropbox - feel free to check it out.
I have answered pretty similar question a while ago - maybe you will also find it useful: Translucent StatusBar with dynamic ActionBar color in Android
I hope, it helps
I was having the same issue, Pier. The annoying thing is there doesn't seem to be any decent guide on showing how to solve this issue, even though it is part of material design guidelines, etc.
Anyway, here is how I did it...
Styles
My
styles.xml
contains a base theme and then my main application theme. I created another theme for my activities that use a navigation drawer like so:The colour
window_background
is referencing mycolors.xml
file, which lists it as#FFF5F5F5
. Note, the above works slightly differently for API 21+, so in thevalues-v21
directory, create anotherstyles.xml
. This one should include the following:Layouts
Now for the layouts. In the layout file you will have your navigation drawer in, you can include the following.
Obviously you can remove the
RelativeLayout
if you don't need any other views inside it, as it would be redundant. The navigation drawer I referenced in my<include>
tag is below:With the above code, you should have your navigation drawer correctly drawing behind the status bar.