I\'m trying to make my navigation drawer go under the status bar. I\'ve read extensively about the ScrimInsetsFrameLayout view and I tried implementing it, but for some reas
adding android:fitsSystemWindows="false" to DrawerLayout will solve the problem
You need to make a new styles.xml and put that file in style-v19 folder because the status bar translucent method is not available for pre kitkat devices.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar" >
<item name="android:windowTranslucentStatus">true</item>
</style>
After that you will see the your Application is under the Status bar But you need to give padding to toolBar for the Exact implementation.Create a dimen-v19 and add
<dimen name="ToolBarPaddingTop">24dp</dimen>
Use it in ToolBar
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/accent_material_light"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:fitsSystemWindows="true"
android:paddingTop="@dimen/ToolBarPaddingTop">
</android.support.v7.widget.Toolbar>
This is what worked for me:
android:windowTranslucentStatus to true in your default style in the v21 folder. This will make your statusbar almost transparent from Lollipop.Toolbar with the android:colorPrimary parameter in your style.android:fitsSystemWindows="true" in your layout.Toolbar and Drawer.There are different approaches to get to the desired result. You can enable translucent via style or via code.
I've created a MaterialDrawer (which follows the Android Material Design Guidelines) which implements all of this and handles everything for you. Read more here: https://github.com/mikepenz/MaterialDrawer/
If you want to create it on your own you always have to decide which is the lowest api you want to support and/or if you have to split up your styles.
So to enable translucentStatusbar you have to be at least on API v19 or you create a separat style for v19+ values-v19
This will look somehow like this
<style name="YourTheme.TranslucentStatus" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
So now this will move your complete layout below the statusbar. In almost all cases you will now want to add the padding on the top of the drawer content and your normal view content.
You can do this by adding 24dp padding.
This is not a really nice implementation. So there's a different approach by using the ScrimInsetsLayout which is used in the Google IO 2014 app. https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget/ScrimInsetsFrameLayout.java
This will be your contents layout and you can set the color for the statusbar on it. You can find a detailed instruction, on how you can use it, here: https://stackoverflow.com/a/26932228
It requires some time to get used to the styles and / or the ScrimInsetsLayout.
EDIT:
A more complex sample on how you can handle this programmatically:
if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
//enable translucent statusbar via flags
setTranslucentStatusFlag(true);
}
if (Build.VERSION.SDK_INT >= 19) {
mActivity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
if (Build.VERSION.SDK_INT >= 21) {
//we don't need the translucent flag this is handled by the theme
setTranslucentStatusFlag(false);
//set the statusbarcolor transparent to remove the black shadow
mActivity.getWindow().setStatusBarColor(Color.TRANSPARENT);
}
//add a padding to the content of the drawer (25dp on devices starting with api v19)
mDrawerContentRoot.setPadding(0, mActivity.getResources().getDimensionPixelSize(R.dimen.tool_bar_top_padding), 0, 0);
// define the statusBarColor
mDrawerContentRoot.setInsetForeground(mStatusBarColor);
private void setTranslucentStatusFlag(boolean on) {
if (Build.VERSION.SDK_INT >= 19) {
Window win = mActivity.getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
if (on) {
winParams.flags |= bits;
} else {
winParams.flags &= ~bits;
}
win.setAttributes(winParams);
}
}
EDIT2:
The complete solution to fix this issue was to clean up all the layouts which were in the project. some combination of the layouts and styles were causing the troubles.
The complete changes can be found in this pull request: https://github.com/Andrew-Quebe/Planets-Gradle/commit/83e28c09253af6e807b6f4e94baca8fbca3fc7c8
I believe you need to add android:fitsSystemWindows="true" to the android.support.v4.widget.DrawerLayout tag as well.