我正在使用工具栏并使用相应操作的选项。我的问题是,我想用白色在工具栏上显示“保存”文本,我应用了许多样式,但总是显示为黑色。但是当选项显示为弹出式时,文本颜色总是白色的。我谷歌这很多,但没有解决方案。当我们使用app时,更改选项菜单的文本颜色:showAsAction =“always”
这里是我的代码:
工具栏
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@android:style/ThemeOverlay.Material.Light"
app:popupTheme="@style/Theme.AppCompat.NoActionBar"
android:background="@drawable/tb_header"
android:minHeight="?attr/actionBarSize"/>
风格
<style name="MStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@android:color/white</item>
<item name="android:colorBackground">@android:color/black</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:textAllCaps">false</item>
<item name="android:popupMenuStyle">@style/MyPopupMenu</item>
<item name="android:panelBackground">@android:color/holo_green_light</item>
<item name="android:actionBarWidgetTheme">@style/AppTheme</item>
</style>
<style name ="MyPopupMenu" parent="android:Theme.Holo.Light">
<item name="android:popupBackground">@android:color/holo_green_light</item>
</style>
****Option menu****
<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="com.doubtfire.userprofiles.ParentProfileActivity">
<item
android:id="@+id/action_skip"
android:title="@string/menu_str_skip"
android:orderInCategory="100"
app:showAsAction="always" />
</menu>
****I even apply code at onPrepareOptionMenu****
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
for (int i=0; i<menu.size(); i++) {
MenuItem mi = menu.getItem(i);
String title = mi.getTitle().toString();
Spannable newTitle = new SpannableString(title);
newTitle.setSpan(new ForegroundColorSpan(Color.WHITE), 0, newTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mi.setTitle(newTitle);
}
return true;
}
这不是工作:( – theLazyFinder
也许我不理解你。你想改变操作栏上的菜单项的文本做什么?是吗?如果是的话这应该工作。你有没有加入你的风格,以清单中的“活动”? –
是的,我想直接说你在说什么,并且我在应用程序标记中的应用程序中添加了这个主题为 – theLazyFinder