如何在菜单中更改背景颜色?

时间:2015-11-02 07:02:18

标签: android xml eclipse menu

如何在菜单中更改背景颜色?默认为白色。我更改了style.xml和菜单,但它显示了白色菜单。 这段代码有什么问题: 我可以删除

    android:theme="@style/your_custom_optionsMenuStyle"

表单manifest.xml,菜单颜色变黑。但我想知道这是好方法吗?在具有不同api的其他设备中它是黑色的吗?     

    <item 
        android:id="@+id/menu_settings"
        android:title="@string/menu_settings"
        android:orderInCategory="100"/>
      <item name="actionOverflowMenuStyle">@style/your_custom_optionsMenuStyle</item>

</menu>

style.xml文件:     &LT;

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

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>



<style name="your_custom_optionsMenuStyle" parent="AppBaseTheme">
 <item name="android:popupBackground">#000000</item>
</style>

 </resources>

清单:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/your_custom_optionsMenuStyle"
      >

2 个答案:

答案 0 :(得分:2)

您可以使用属性

从样式xml文件覆盖应用主题中的菜单样式
<item name="actionOverflowMenuStyle">@style/your_custom_optionsMenuStyle</item>

其中your_custom_optionsMenuStyle指定每个菜单属性的行为

<style name="your_custom_optionsMenuStyle" parent="Widget.AppCompat.PopupMenu.Overflow">
     <item name="android:popupBackground">your color code</item>
</style>

答案 1 :(得分:0)

您需要在图标上设置样式。我更愿意看到以下链接有助于How to change the background color of Action Bar's Option Menu in Android 4.2?