在api 8上更改材料设计的菜单背景颜色

时间:2015-08-26 09:00:09

标签: android material-design

我是Android新手,编写了我的第一个使用操作栏和设计支持库的应用程序。但是,当我展开菜单时,它具有黑色背景颜色。在我应用材质设计之前,菜单具有默认的灰色。我的colors.xml文件中没有任何深色。我怎样才能恢复正常颜色? 下面是我在styles.xml中创建的主题:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>            
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>            
        <item name="colorAccent">@color/colorAccent</item>            
        <item name="android:textColorPrimary">@color/textColorPrimary</item>            
        <item name="android:textColorSecondary">@color/textColorSecondary</item>           
    </style>

当我删除工具栏中的应用主题时,我会恢复正常颜色,但操作栏文本和3个垂直点的颜色会变为黑色。以下是我的activity_main的相关部分:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

非常简单。要更改操作栏弹出菜单的背景,请将以下属性添加到<android.support.v7.widget.Toolbar标记

app:popupTheme="@style/ThemeOverlay.AppCompat.Light"

您可以使用默认样式或使用更具体的颜色创建自己的样式。