4

独自のアクション アイテムを作成しようとしてきましたが、私には不可能でした。

私がやろうとしているのは、「親指」アクションバーのようなカスタム アクション アイテム レイアウト (たとえば、色付きの背景) を作成することです。アクティビティの 1 つのアクション アイテムのみを変更したい。

ここに画像の説明を入力

アクションメニュー項目の android:icon および android:actionLayout プロパティで遊んでいますが、何も得られませんでした。

実は、StackOverflow で別のスレッドを見たことがありますが、役に立ちませんでした...

ActionBarSherlock でカスタム レイアウトを使用して ActionMode を構築する

スタイリング ActionbarSherlock: アクション項目の textColor

何か案は?前もって感謝します!

4

1 に答える 1

12

ActionBarSherlockテーマを上書きするには、次のように進める必要があります。

ライブラリプロジェクトvalues/abs__themes.xmlから開きます。ActionBarSherlockたとえば、次のように表示されます。

<style name="Theme.Sherlock" parent="Sherlock.__Theme">
    <!-- Action bar styles (from Theme.Holo) -->
    <item name="actionDropDownStyle">@style/Widget.Sherlock.Spinner.DropDown.ActionBar</item>
    <item name="actionButtonStyle">@style/Widget.Sherlock.ActionButton</item>
    <item name="actionOverflowButtonStyle">@style/Widget.Sherlock.ActionButton.Overflow</item>
    <item name="actionModeBackground">@drawable/abs__cab_background_top_holo_dark</item>
    <item name="actionModeSplitBackground">@drawable/abs__cab_background_bottom_holo_dark</item>
    <item name="actionModeCloseDrawable">@drawable/abs__ic_cab_done_holo_dark</item>
    <item name="actionBarTabStyle">@style/Widget.Sherlock.ActionBar.TabView</item>
    ...
    // Here is what you wanted
    <item name="actionBarItemBackground">@drawable/abs__item_background_holo_dark</item>
    ...

カスタマイズしたいアイテム(actionBarItemBackgroundあなたの場合)を見つけたらthemes.xml、プロジェクト内に独自のアイテムを作成し、それに追加します。

<style name="Custom.Theme.Sherlock" parent="@style/Theme.Sherlock">
    <item name="actionBarItemBackground">@drawable/my__item_background_holo_dark</item>
</style>

これはデフォルトを上書きしTheme.Sherlock、カスタムを設定しますactionBarItemBackground

Theme.Sherlockこれで、アクティビティで使用する代わりに、を使用する必要がありますsetTheme(R.style.Custom_Theme_Sherlock)Theme.Sherlock.Light他の2つのテーマ(およびTheme.Sherlock.Light.DarkActionBar)をオーバーライドすることもできます

もう1つのヒントはActionBarSherlock、デフォルトのアクションアイテムの背景(holo_light内)に使用されるドローアブルセレクターです。これは、9パッチのpngドローアブルを使用します。

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/abs__list_selector_disabled_holo_light" />
<item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/abs__list_selector_disabled_holo_light" />
<item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/abs__list_selector_background_transition_holo_light" />
<item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/abs__list_selector_background_transition_holo_light" />
<item android:state_focused="true"                                                             android:drawable="@drawable/abs__list_focused_holo" />
<item                                                                                          android:drawable="@android:color/transparent" />


その他の基本的なカスタマイズには、このツールを使用できます。スタイルが生成されます。

于 2012-09-18T12:32:45.440 に答える