如何风格在Android操作栏上的菜单项

问题描述:

还有的是在造型上的动作条的许多问题,但那些我发现无论是与样式选项卡,或者有答案,不为我工作。

There's been many questions on styling on action bars, but the ones I've found either are relating to styling the tabs, or have answers that don't work for me.

现在的问题是很简单的。我希望能够改变菜单项的文本样式(甚至只是颜色)的操作栏。

The question is really quite simple. I want to be able to change the text styling (even just colour) of the menu items in the action bar.

我读过这样的: http://android-developers.blogspot.com/2011/04/customizing-action-bar.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+blogspot%2FhsDu+%28Android+Developers+Blog%29

和这个问题: 风格的操作栏在Android的蜂窝

这是我已经把我使用尝试并获得菜单项来更改测试应用程序。它使用所有的默认值在Eclipse的Andr​​oid插件创建一个应用程序,除了以下。

From which I have put together a test application that I am using to try and get the menu items to change. It uses all the default values for an app created in the eclipse android plugin, except for the following.

一个款式文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:titleTextStyle">@style/MyActionBar.TitleTextStyle</item>
    <item name="android:actionMenuTextAppearance">@style/MyActionBar.MenuTextStyle</item>
</style>

<style name="MyActionBar.TitleTextStyle"
    parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">#F0F</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textSize">24dip</item>
</style>

<style name="MyActionBar.MenuTextStyle"
    parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">#F0F</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textSize">24dip</item>
</style>
</resources>

的操作栏菜单:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:showAsAction="always|withText" android:icon="@android:drawable/ic_menu_edit"
    android:id="@+id/menu_item1" android:title="menu_item1"></item>

<item android:showAsAction="always|withText" android:icon="@android:drawable/ic_menu_edit"
    android:id="@+id/menu_item2" android:title="menu_item2"></item>

</menu>

主要活动:

public class Main extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

/**
 * Create the options menu that is shown on the action bar
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);
    return true;
}
}

应用程序编译和运行。在造型的操作栏标题文字作品完美(就是粉红色#F0F可爱的树荫下,我定义)。该菜单项不会改变出现,但与默认样式(全息光)。

The application compiles and runs. The styling for the action bar title text works perfectly (is that lovely shade of pink #F0F I've defined). The menu items do not change appear but with default styling (holo light).

我是什么做错了吗?

我知道,这个被要求在很久以前,但想我还是会回答。而不是由机器人:actionMenuTextAppearance 项下你的动作条的风格,将它在你的应用程序的主题

I know that this was asked a long time ago but figured I'd still answer. Instead of having the android:actionMenuTextAppearance item under your action bar style, move it under your app theme.