【问题标题】:Android color background OptionMenuAndroid 彩色背景 OptionMenu
【发布时间】:2015-05-23 16:14:08
【问题描述】:

我想更改 OptionMenu 的背景颜色。我使用 ToolBar 并创建了 Theme,但 OptionMenu 的背景颜色没有改变。怎么了?

工具栏

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
android:popupTheme="@style/Toolbar_Popup"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/ColorPrimary"
android:elevation="2dp"/>

样式

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/ColorPrimary</item>
    <item name="colorPrimaryDark">@color/ColorPrimaryDark</item>

</style>

<!-- PopUp theme. -->
<style name="Toolbar_Popup" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:textColorPrimary">#ffffff</item>
    <item name="android:background">@color/ColorPrimary</item>
</style></resources>

【问题讨论】:

    标签: android colors background toolbar


    【解决方案1】:

    对我来说效果很好。您是否尝试过清理和重建?

    activity_main.xml
    `    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout 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"
        tools:context="com.example.siwarak.toolbar.MainActivity">
    
        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
            android:popupTheme="@style/Toolbar_Popup"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:background="@color/colorAccent"
            android:elevation="2dp"/>
    
    
    </android.support.constraint.ConstraintLayout>
        `
    

    style.xml

    <resources>
    
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    
    
    
    <!-- PopUp theme. -->
    <style name="Toolbar_Popup" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:textColorPrimary">#ffffff</item>
        <item name="android:background">@color/colorPrimary</item>
    </style>
    

    【讨论】: