我使用的是一个自定义主题,继承自DarkActionBar,我想自定义下拉菜单为白色时,就像使用轻全息主题。
我已经能够使用以下命令将背景更改为白色:
<style name="MyTheme" parent="@style/Theme.Light.DarkActionBar">
<item name="android:actionDropDownStyle">@style/MyDropDownNav</item>
</style>
<style name="MyDropDownNav">
<item name="android:background">@drawable/spinner_background_white</item>
<item name="android:popupBackground">@drawable/menu_dropdown_panel_whyite</item>
<item name="android:dropDownSelector">@drawable/selectable_background_white</item>
</style>但我不知道如何将文本颜色更改为黑色。因为在设置白色可绘制之后,问题是文本是不可见的,因为在白色背景上是白色的。
发布于 2012-07-14 18:51:40
经过一番调查后,我回答了自己。除了问题的样式之外,你还需要:
android:spinnerDropDownItemStyle actionBarWidgetTheme changing‘s text appearance.simple_dropdown_item_1line),那就没有问题了。但如果你使用的是像我这样的自定义工具(为了能够添加图标),别忘了在你的layout TextView中应用 style="?attr/spinnerDropDownItemStyle"。那么最终的自定义样式是:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.myapp" parent="@style/Theme.Light.DarkActionBar">
<item name="android:actionDropDownStyle">@style/myapp_DropDownNav</item>
<item name="android:actionBarWidgetTheme">@style/myapp.actionBarWidgetTheme</item>
</style>
<style name="myapp.actionBarWidgetTheme" parent="@style/Theme.">
<item name="android:spinnerDropDownItemStyle">@style/myapp.Widget.DropDownItem.Spinner</item>
</style>
<style name="myapp_DropDownNav" parent="@style/Widget.Spinner.DropDown.ActionBar">
<item name="background">@drawable/spinner_background_ab_myapp</item>
<item name="android:background">@drawable/spinner_background_ab_myapp</item>
<item name="android:popupBackground">@drawable/menu_dropdown_panel_myapp</item>
<item name="android:dropDownSelector">@drawable/selectable_background_myapp</item>
</style>
<style name="myapp.Widget.DropDownItem.Spinner" parent="Widget.DropDownItem.Spinner">
<item name="android:textAppearance">@style/myapp.TextAppearance.Widget.DropDownItem</item>
</style>
<style name="myapp.TextAppearance.Widget.DropDownItem" parent="TextAppearance.Widget.DropDownItem">
<item name="android:textColor">@color/black</item>
</style>
其中,myapp_DropDownNav中的可绘制内容是可以在Android Asset Studio中使用ActionBar Style generator生成的白色背景内容
发布于 2012-07-14 06:59:32
尝试设置itemTextAppearance。这应该会达到你想要的效果。
发布于 2014-05-08 13:17:15
我偶然发现了做这件事最简单的方法。我正在使用AppCompat库。
<style name="ApplicationTheme" parent="@style/Theme.AppCompat">
<item name="android:actionBarWidgetTheme">@style/Theme.AppCompat.Light</item>
<item name="actionBarWidgetTheme">@style/Theme.AppCompat.Light</item>
</style>https://stackoverflow.com/questions/11479186
复制相似问题