状态栏未覆盖导航抽屉

时间:2016-06-08 09:25:56

标签: android android-layout navigation-drawer

我在导航抽屉中有ImageView,而我还没有状态栏来覆盖它。我尝试了一些来自互联网和stackoverflow的指令,包括" fitsSystemWindos = true",添加半透明标志,但没有任何作用。有人可以帮忙吗? (BTW,min api 21,在棉花糖上测试)

此外我还有滚动问题,它只是没有工作

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>

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" />

来自MainActivity.java的一些行

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

enter image description here

1 个答案:

答案 0 :(得分:0)

所以,我决定拒绝使用ImageView,只是把我的图像作为背景(下面有空白区域)也许我的代码可以帮助某人(但是,嘿,更好地找到更有用的解决方案)

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));
    }