代码之家  ›  专栏  ›  技术社区  ›  Jack

导航抽屉视图背景颜色显示黑色背景

  •  0
  • Jack  · 技术社区  · 6 年前

    我正面临一个棘手的问题,我在我的应用程序中有一个导航抽屉活动,当应用程序运行在API 21以下时,我发现了一些工具栏错误。我通过更改工具栏来修复它颜色。还有不小心导航抽屉的颜色变成了黑色。我不知道它是怎么变成黑色的。

    这是导航视图

    <?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"
    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_home_page_new"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_home_page_new"
        app:menu="@menu/activity_home_page_new_drawer" />
    

     and the toolbar layout
    
    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    tools:context=".NEWUI.HomePageNew">
    
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
    
        <android.support.v7.widget.Toolbar
          android:id="@+id/toolbar"
          android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
          android:background="?attr/colorPrimary"
          app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.design.widget.AppBarLayout>
    
    <include layout="@layout/content_home_page_new" />
    
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:backgroundTint="@color/colorFab"
        app:srcCompat="@drawable/ic_fab_svg" />
     </android.support.design.widget.CoordinatorLayout>
    

    我的颜色是原色、原色和强调色

     <color name="colorPrimary">#2B2B2B</color>
    <color name="colorPrimaryDark">#2B2B2B</color>
    <color name="colorAccent">#FFF</color>
    

    <resources xmlns:android="http://schemas.android.com/apk/res/android">
    
    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>
    
    
    <style name="AppTheme" parent="AppTheme.Base">
        <!-- 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="treeViewListStyle" parent="android:style/Widget.ListView">
        <item name="android:background">@android:color/white</item>
        <item name="android:divider">@drawable/divider</item>
    </style>
    
    <!--  Transparent dialog -->
    <style name="TransparentProgressDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowTitleStyle">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
        <item name="android:backgroundDimEnabled">true</item>
        <item name="android:background">@android:color/transparent</item>
    </style>
    
    <style name="TabLargeTextTheme" parent="@android:style/Theme">
        <item name="android:tabWidgetStyle">@style/TabLargeWidget</item>
    </style>
    
    <style name="TabLargeWidget" parent="@android:style/Widget.TabWidget">
        <item name="android:textAppearance">@style/TabLargeWidgetText</item>
    </style>
    
    <style name="TabLargeWidgetText" parent="@android:style/TextAppearance.Widget.TabWidget">
        <item name="android:textSize">16sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textAllCaps">true</item>
    </style>
    
    <style name="alert_dialog" parent="android:Theme.Dialog">
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowIsTranslucent">false</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">false</item>
        <item name="android:windowBackground">@color/float_transparent</item>
        <item name="android:windowAnimationStyle">@null</item>
        <item name="android:backgroundDimEnabled">true</item>
        <item name="android:backgroundDimAmount">0.4</item>
    </style>
    
    <style name="dialog_blue_button" parent="android:Widget.Button">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">31dp</item>
        <item name="android:background">@drawable/blue_button_background</item>
        <item name="android:textSize">14sp</item>
        <item name="android:paddingLeft">21dp</item>
        <item name="android:paddingRight">21dp</item>
        <item name="android:textColor">@color/black</item>
    </style>
    
    <!--Style for the normal font to be used across the application -->
    <style name="style_medium_font">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
    </style>
    
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    <!--Style for the font to be used in buttons -->
    <style name="style_button_font">
        <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
           <item name="android:textColor">@android:color/primary_text_dark</item>
          <item name="android:background">#CC000000</item>
         </style>
    
          <style name="style_pwd_dialog_button_font" 
            parent="style_button_font">
            <item name="android:textAppearance">? 
           android:attr/textAppearanceMedium</item>
            </style>
    
         <style name="AppTheme.AppBarOverlay" 
         parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    
        <style name="AppCompatAlertDialogStyle" 
        parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorAccent">#FFCC00</item>
        <item name="android:textColorPrimary">#FFFFFF</item>
        <item name="android:background">#5fa3d0</item>
    </style>
    
    <style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    
    <!--<style name="ToolBarStyle" parent="">-->
    <!--<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>-->
    <!--<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>-->
    <!--</style>-->
    
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
    
     <style name="TextLabel" parent="TextAppearance.Design.Hint">
        <item name="android:textSize">10sp</item>
           </style>
            </resources>
    

    2 回复  |  直到 6 年前
        1
  •  0
  •   mike    6 年前

    尝试更改背景色调:

    <android.support.design.widget.NavigationView
     android:id="@+id/nav_view"
     android:layout_width="wrap_content"
     android:layout_height="match_parent"
     android:layout_gravity="start"
     android:fitsSystemWindows="true"
     app:headerLayout="@layout/nav_header_home_page_new"
     app:menu="@menu/activity_home_page_new_drawer"
     android:backgroundTint="#ffffff"/>
    
        2
  •  0
  •   user8959091 user8959091    6 年前

    使用 android:background app:itemBackground

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_home_page_new"
        app:menu="@menu/activity_home_page_new_drawer"
        app:itemBackground="@android:color/transparent"
        android:background="@color/your_color" />