[英]how to change color of background in 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文件:<
<!--
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"
>
您可以使用属性从样式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>
您需要在图标上设置样式。我希望看到下面的链接会有所帮助。 如何在Android 4.2中更改操作栏的选项菜单的背景颜色?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.