2016-07-19 138 views
1

我正在使用NavigationView和工具栏。状态栏的背景是白色的。如果您有任何问题,只需在投票之前发表评论,我会尽快查看。使用自定义工具栏时状态栏变为白色

activity_main.xml中

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

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

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

    <FrameLayout 
     android:id="@+id/flContent" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nvView" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:background="@android:color/white" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_main_drawer/> 
    </android.support.v4.widget.DrawerLayout> 

app_bar_main.xml

<android.support.v7.widget.Toolbar 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/toolbar" 
android:layout_height="wrap_content" 
android:layout_width="match_parent" 
android:fitsSystemWindows="true" 
android:minHeight="?attr/actionBarSize" 
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
android:background="?attr/colorPrimaryDark"> 
</android.support.v7.widget.Toolbar> 

styles.xml

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style> 

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

colors.xml

<resources> 
    <color name="colorPrimary">#3F51B5</color> 
    <color name="colorPrimaryDark">#303F9F</color> 
    <color name="colorAccent">#FF4081</color> 
</resources> 
+1

尝试类似:'机器人:fitsSystemWindows = “假”' – ArbenMaloku

+0

你定义@色/ colorPrimaryDark如何做(在colors.xml )? – W0rmH0le

+0

上传你的color.xml文件 –

回答

2

您必须添加此属性机器人:fitsSystemWindows = “真”父(DrawerLayout)。在使用它时修复白色状态栏。

为了更多地了解它是指该链接Why would I want to fitsSystemWindows?

<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" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true"> 

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

    <include 
     android:id="@+id/toolbar" 
     layout="@layout/tool_bar" /> 

    <FrameLayout 
     android:id="@+id/Holder" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</LinearLayout> 

<android.support.design.widget.NavigationView 
    android:id="@+id/navigation" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    app:headerLayout="@layout/navigation_header" 
    app:itemTextColor="@color/primary_dark" 
    app:menu="@menu/my_navigation_items" /> 

+0

哇,这是否简单?非常感谢你。 –

+0

是的,非常简单 – JUL2791