【发布时间】:2016-10-31 22:46:58
【问题描述】:
我有一个在 3 种不同活动中膨胀到工具栏上的菜单。其中一项活动有一个溢出菜单,溢出后面有一个操作。 我可以更改动作的背景颜色。我无法更改与动作关联的文本的文本颜色。请不要投反对票,我已经查看并尝试了所有 136 个类似的发布问题。 下面是样式代码和菜单代码。
<resources>
<!-- Base application theme. -->
<!-- parent="Theme.AppCompat.NoActionBar"> -->
<!-- Line of CODE ABOVE gives WHITE color to items in ToolBar -->
<!-- Line of CODE BELOW gives BLACk color to items in ToolBar -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:itemBackground">@color/color_Red</item>
<item name="actionMenuTextColor">@style/MyActionBarTitleText</item>
</style>
<style name="MyActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/color_Yellow</item>
</style>
菜单代码
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/action_ReSetPW"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"
android:visible="true"/>
作为旁注,我也无法根据某些参数更改标题文本颜色。我想知道如何设置或更改文本颜色? 经过一些试验和错误后,我发布了一个带有 cmets 的样式代码,用于下面的解决方案代码
<resources>
<!-- Base application theme. -->
<!-- parent="Theme.AppCompat.NoActionBar"> -->
<!-- Line of CODE ABOVE gives WHITE color to items in ToolBar -->
<!-- Line of CODE BELOW gives BLACk color to items in ToolBar -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:itemBackground">@color/color_Red</item>
<!--The line of CODE above styles the action background color -->
</style>
<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">21sp</item>
<item name="android:textStyle">italic</item>
</style>
<!--ADD THIS TO THE XML that defines the widget ToolBar android:theme="@style/ToolbarTheme" -->
<!--the line of CODE above tells the ToolBar where to find the style to use -->
<!--Code below will make the Overflow three dots Yellow and the text of the Action Yellow -->
<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">@color/color_Yellow</item>
</style>
似乎解决方案的一部分是从toolbar.xml调用样式
【问题讨论】:
标签: android menu android-actionbar