Dima Rostopira Dima Rostopira - 5 months ago 36
Android Question

Status bar not covering the Navigation Drawer

I have ImageView in Navigation Drawer, and I wan't status bar to overlay it. I have tried some instruction from internet and stackoverflow including "fitsSystemWindos=true", add translucent flag, but nothing works. Can somebody help? (BTW, min api 21, testing on Marshmallow)

Also I have problem with scrolling, it just doesn't work

v21/styles.xml

<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>


First part of activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<!--Drawer Layout-->
<ScrollView
android:layout_width="240dp"
android:layout_height="match_parent"
android:background="@android:color/white"
android:layout_gravity="start"
android:fillViewport="true"
android:overScrollMode="always"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Header -->
<ImageView
android:layout_width="match_parent"
android:layout_height="180dp"
android:src="@drawable/example"
android:id="@+id/drawer_header"
android:onClick="selfEdit"
android:layout_gravity="top"
android:scaleType="centerCrop" />


And some lines from MainActivity.java

Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(0x80000000);


enter image description here

Answer

So, I decided to decline ImageView and just put my image as background (with white space below it) Maybe my code will help someone (but hey, better find more usable solution)

public static void setDrawerBackground(MainActivity activity, Bitmap 
        if (bitmap==null)
            return;
        Point p = new Point();
        activity.getWindowManager().getDefaultDisplay().getSize(p);
        Bitmap b = Bitmap.createBitmap(activity.findViewById(R.id.drawer).getWidth(), p.y, bitmap.getConfig());
        Canvas canvas = new Canvas(b);
        canvas.drawColor(Color.WHITE);
        Matrix m = new Matrix();
        float scale = b.getWidth()/bitmap.getWidth();
        m.setScale(scale, scale);
        canvas.drawBitmap(bitmap, m, null);
        activity.findViewById(R.id.drawer).setBackground(new BitmapDrawable(b));
    }