【问题标题】:Status bar not covering the Navigation Drawer状态栏未覆盖导航抽屉
【发布时间】:2016-06-12 18:36:58
【问题描述】:

我在导航抽屉中有 ImageView,我不想用状态栏覆盖它。我已经尝试了一些来自互联网和 stackoverflow 的指令,包括“fitsSystemWindos = true”,添加半透明标志,但没有任何效果。有人可以帮忙吗? (顺便说一句,最小 api 21,在 Marshmallow 上测试)

我也有滚动的问题,它只是不起作用

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

【问题讨论】:

  • 老兄,你的应用中有什么样的可绘制对象? @Dima
  • @ankitagrawal ImageView 来自 PNG。抱歉,忘记添加截图
  • 可以加截图吗?
  • 尝试添加 true
  • @TusharSheth 应用程序现在全屏,状态栏隐藏,当我让他可见时 - 它是黑色的

标签: android android-layout navigation-drawer


【解决方案1】:

所以,我决定拒绝 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));
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-30
    • 2014-12-27
    相关资源
    最近更新 更多