65

アクション バーのスタイル設定について多くの質問が寄せられていますが、タブのスタイル設定に関するものか、私にとってはうまくいかない回答が見つかりました。

質問は実にシンプルです。アクション バーのメニュー項目のテキスト スタイル (色だけでも) を変更できるようにしたいと考えています。

私はこれを読みました: 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 Android プラグインで作成されたアプリのすべてのデフォルト値を使用します。

スタイル ファイル:

<?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 です)。メニュー項目の表示は変わりませんが、デフォルトのスタイル (ホロ ライト) が適用されます。

私は何を間違っていますか?

4

8 に答える 8

64

android:actionMenuTextAppearanceアクション バー スタイルの下に項目を配置する代わりに、アプリのテーマの下に移動します。

于 2012-06-12T15:20:44.923 に答える
5

あなたは変わらなければならない

<style name="MyActionBar.MenuTextStyle"
parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">

<style name="MyActionBar.MenuTextStyle"
parent="android:style/TextAppearance.Holo.Widget.ActionBar.Menu">

同じように。これは私にとってはうまくいきます。

于 2012-03-05T16:51:48.343 に答える
5

以下のコードだと思います

<item name="android:actionMenuTextAppearance">@style/MyActionBar.MenuTextStyle</item> 

セクションにある必要がありますMyAppTheme

于 2011-12-19T14:10:06.610 に答える
4

クリスの答えは私のために働いています...

私のvalues-v11/styles.xmlファイル:

<resources>
<style name="LightThemeSelector" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/ActionBar</item>
    <item name="android:editTextBackground">@drawable/edit_text_holo_light</item>
    <item name="android:actionMenuTextAppearance">@style/MyActionBar.MenuTextStyle</item>
</style>

<!--sets the point size to the menu item(s) in the upper right of action bar-->
<style name="MyActionBar.MenuTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textSize">25sp</item>
</style>

<!-- sets the background of the actionbar to a PNG file in my drawable folder. 
displayOptions unset allow me to NOT SHOW the application icon and application name in the upper left of the action bar-->
<style name="ActionBar" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:background">@drawable/actionbar_background</item>
    <item name="android:displayOptions"></item>
</style>

<style name="inputfield" parent="android:Theme.Holo.Light">
    <item name="android:textColor">@color/red2</item>
</style>  
</resources>
于 2013-06-25T22:16:46.337 に答える
1

onCreateOptionsMenu() のメニュー情報から生成されるビューのスタイルも設定する必要があると思います。これまでに適用したスタイリングは機能していますが、メニュー項目がテキストでレンダリングされたときに、ActionBar のタイトル部分と同じスタイルを使用しているとは思えません。

Menu.getActionView() を見て、メニュー アクションのビューを取得し、それに応じて調整することができます。

于 2011-08-03T17:40:43.210 に答える