我正在尝试使用Material主题并更改菜单和项目的背景和文本颜色。使用下面的样式它可以在工具栏上正常工作,但是按下设备菜单按钮弹出菜单显示文本颜色没有变化,尽管背景已经改变。请帮助改变上面提到的文字颜色。
<resources>
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
</style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorPrimary">@color/accent</item>
<item name="android:textColorSecondary">@color/accent</item>
<item name="android:textColorHint">@color/accent</item>
<!-- Menu Items -->
<item name="android:textColor">@color/accent</item>
<item name="android:actionMenuTextColor">@color/accent</item>
<item name="actionMenuTextColor">@color/accent</item>
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="android:itemBackground">@color/colorPrimaryDark</item>
<item name="android:itemTextAppearance">@style/MyActionBar.MenuTextStyle</item>
<!-- Menu Items -->
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">@color/colorPrimaryDark</item>
<item name="titleTextStyle">@style/MyActionBarTitle</item>
<item name="actionMenuTextColor">@color/accent</item>
</style>
<style name="MyActionBarTitle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/accent</item>
<item name="android:actionMenuTextColor">@color/accent</item>
<item name="actionMenuTextColor">@color/accent</item>
</style>
<style name="MyActionBar.MenuTextStyle">
<item name="android:textColor">@color/accent</item>
<item name="android:textStyle">bold</item>
<item name="android:actionMenuTextColor">@color/accent</item>
<item name="actionMenuTextColor">@color/accent</item>
</style>
答案 0 :(得分:5)
主题中的一个简单的行:)
<item name="android:actionMenuTextColor">@color/your_color</item>
答案 1 :(得分:5)
尝试创建此主题
<style name="TextAppearance" parent="@style/Theme.Sherlock.Light">
<item name="actionMenuTextColor">@color/white</item>
<item name="android:actionMenuTextColor">@color/white</item>
</style>
比在此活动主题中应用此主题
<style name="your_theme" parent="your_parent">
<item name="android:itemTextAppearance">@style/TextAppearance</item>
</style>
或尝试此
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.your_menu, menu);
int positionOfMenuItem = 0;
MenuItem item = menu.getItem(positionOfMenuItem);
SpannableString s = new SpannableString("My red MenuItem");
s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0);
item.setTitle(s);
}
答案 2 :(得分:1)
在主题中添加一条简单的线。希望这可以解决您的问题。
<item name="android:textColor">@color/button_color</item>
享受..
答案 3 :(得分:0)
您可以通过在style.xml中添加新样式来更改溢出菜单背景的颜色。
<style name="OverflowMenu"
parent="@android:style/Theme.Holo">
<item name="android:popupMenuStyle">@style/MyOverflowMenu</item>
<item name="android:itemTextAppearance">@style/TextAppearance</item>
</style>
<style name="MyOverflowMenu"
parent="@android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">@color/your_color</item>
</style>
<style name="TextAppearance">
<item name="android:textColor">@color/your_color</item>
</style>
答案 4 :(得分:0)
// note if you want to style popup menu in toolbar
step 1-- Add your theme in toolbar
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/MyPopupTheme" />
step 2-- add style in styles.xml
<style name="MyPopupTheme" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:colorControlActivated">@color/red </item>
<item name="android:colorControlHighlight">@color/red</item>
<item name="android:colorControlNormal">@color/yellow</item>
<item name="android:textColorPrimary">@color/yellow</item>
</style>
// note if you want to style menu text color in toolbar itself
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/Mytoolbartheme"/ />
<style name="Mytoolbartheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionMenuTextColor">@color/text_color</item>
</style>
// if you use android x then toolbar is
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:id="@+id/toolbar"
app:titleTextColor="@color/white"
app:popupTheme="@style/MyPopupTheme"
android:background="@color/colorsplash"
android:layout_height="wrap_content">
</androidx.appcompat.widget.Toolbar>