简体   繁体   English

在Android Kitkat 4.4版本的状态栏下使用导航抽屉时,状态栏颜色显示为白色但不透明

[英]status bar colour shows white not transparent while using navigation drawer under status bar in Android Kitkat 4.4 version

i am using material design navigation drawer in which i want to make my drawerlayout under transparent status bar in android kitkat 4.4 version for that i have used fitsystemwindow true but when using fitsystem window true it shows white statusbar also i have used android:windowTranslucentStatus true and android:windowTranslucentNavigation false in my style.xml under values-v19 but still it showing me white status bar in android kitkat 4.4 it's easy to achive in lolipop that i know for statusbar so how to make statusbar transparent in android kitkat 4.4 i have googling lots of for that but non of solution is worked for me.please help me to resolve this issue.Thanks in Advance. 我正在使用材质设计导航抽屉,其中我想在android kitkat 4.4版本的透明状态栏下创建我的抽屉布局,因为我已经使用过fitsystemwindow true,但是当使用fitsystem window true时,它也显示了白色statusbar我也使用过android:windowTranslucentStatus true和android:windowTranslucentNavigation在值-v19下的style.xml中为false,但仍向我显示android kitkat 4.4中的白色状态栏,很容易在lolipop中获得我对statusbar的了解,因此如何在Android kitkat 4.4中使statusbar透明我有很多谷歌搜索,但非解决方案适用于我。请帮助我解决此问题。谢谢。

values-v19/style.xml values-v19 / style.xml

 <resources xmlns:android="http://schemas.android.com/tools">

        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="android:windowTranslucentStatus">true</item>
            <item name="android:windowTranslucentNavigation">false</item>


        </style>

    </resources>

activity_main.xml 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:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinator"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:paddingTop="5dp"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:theme="@style/ThemeOverlay.AppCompat.Dark" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tablayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?attr/colorPrimary"
                android:theme="@style/ThemeOverlay.AppCompat.Dark"
                app:tabGravity="fill"
                app:tabIndicatorColor="#f8f880"
                app:tabSelectedTextColor="#ff8800"
                app:tabTextColor="#ffffff" />

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </LinearLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_gravity="bottom|right"
            android:layout_marginBottom="@dimen/activity_vertical_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:src="@drawable/ic_done" />

    </android.support.design.widget.CoordinatorLayout>


    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#ffffff"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/drawer" />
</android.support.v4.widget.DrawerLayout>

For API 21+ 对于API 21+

<style name="AppTheme" parent="android:Theme.Holo.NoActionBar.TranslucentDecor">
    ...
</style>

For API level 19+ 对于API级别19+

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowTranslucentStatus">true</item>
</style>

Also your layout should have android:fitsSystemWindows="false" 此外,您的布局还应具有android:fitsSystemWindows="false"

NOTE: In Android KitKat you cannot change the color of the status bar except if you use the following solution because only in Lollipop Google introduced the attribute statuBarColor 注意:在Android KitKat中,除非使用以下解决方案,否则无法更改状态栏的颜色,因为仅在Lollipop中,Google引入了statuBarColor属性

So for that you need to check this transparent status bar in KITKAT 因此,您需要在KITKAT中检查此透明状态栏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM