在我的主应用主题上,我有:
<item name="android:popupMenuStyle">@style/MyApp.PopupMenu</item>
<item name="android:textAppearanceLargePopupMenu">@style/MyTextAppearanceLargePopupMenu
</item>
<item name="android:textAppearanceSmallPopupMenu">@style/MyTextAppearanceSmallPopupMenu
</item>
然后我有
<style name="MyApp.PopupMenu" parent="Base.Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">@color/white</item>
<item name="android:textColorPrimary">@color/black</item>
<item name="android:textColorSecondary">@color/black</item>
<item name="android:textColor">@color/black</item>
<item name="android:background">@color/color_white</item>
<item name="overlapAnchor">true</item>
<item name="android:overlapAnchor">true</item>
<item name="android:textAppearanceLargePopupMenu">@style/MyTextAppearanceLargePopupMenu
</item>
<item name="android:textAppearanceSmallPopupMenu">@style/MyTextAppearanceSmallPopupMenu
</item>
</style>
<style name="MyTextAppearanceLargePopupMenu" parent="TextAppearance.AppCompat.Widget.PopupMenu.Large">
<item name="android:textColor">@color/black</item>
</style>
<style name="MyTextAppearanceSmallPopupMenu" parent="TextAppearance.AppCompat.Widget.PopupMenu.Small">
<item name="android:textColor">@color/black</item>
</style>
但是我的弹出菜单显示为白色背景和白色字母而不是黑色。我通过改变背景测试了这一点,并且工作正常。
那么我做错了什么?
感谢。
编辑:想出来,我的应用主题有<item name="android:textColor">@color/primary_text</item>
,这似乎覆盖了我在弹出菜单样式上做的任何事情。
答案 0 :(得分:0)
以下是一个例子:
<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>
<item name="popupMenuStyle">@style/PopupStyle</item>
<item name="textAppearanceLargePopupMenu">@style/PopupTextAppearanceLarge</item>
<item name="textAppearanceSmallPopupMenu">@style/PopupTextAppearanceSmall</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">@android:color/white</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="android:colorBackground">#ff00ff</item>
</style>
<style name="PopupStyle" parent="Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">#ff00ff</item>
</style>
<style name="PopupTextAppearanceLarge" parent="TextAppearance.AppCompat.Light.Widget.PopupMenu.Large">
<item name="android:textColor">#ffff00</item>
</style>
<style name="PopupTextAppearanceSmall" parent="TextAppearance.AppCompat.Light.Widget.PopupMenu.Small">
<item name="android:textColor">#ffff00</item>
</style>
</resources>
工具栏示例:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
答案 1 :(得分:0)
很晚了,但主要原因是属性 android:textColor
应用于在主样式(父)中定义的弹出菜单,您无法通过定义弹出菜单的样式来控制。不知道这个奇怪功能的原因,但它是 google 。
所以在父样式中添加 <item name="android:textColor">@color/white</item>
。