2012-08-14 30 views
6

私は今この問題を何日間か悩まされています。誰も私がActionBar(NavigationModeはNAVIGATION_MODE_TABS)の下に表示されたタブをカスタマイズするのを助けることができますか?ActionBar TabBar(ActionBarSherlock)をカスタマイズする

基本的には、タブの背景色と現在選択されているタブの下線色を変更する必要があります。これまでのところ、これは私がやったことですが、うまくいきません。私はActionBarSherlockを使用しています。

<style name="Theme.Styled" parent="@style/Theme.Sherlock.Light"> 
    <item name="actionBarStyle">@style/Widget.Theme.Styled.ActionBar</item> 
    <item name="android:actionBarStyle">@style/Widget.Theme.Styled.ActionBar</item> 

    <item name="actionBarTabBarStyle">@style/customActionBarTabStyle</item> 
    <item name="android:actionBarTabBarStyle">@style/customActionBarTabStyle</item> 

    <item name="actionBarTabBarStyle">@style/customActionBarTabBarStyle</item> 
    <item name="android:actionBarTabBarStyle">@style/customActionBarTabBarStyle</item> 

    <item name="actionBarTabTextStyle">@style/customActionBarTabTextStyle</item> 
    <item name="android:actionBarTabTextStyle">@style/customActionBarTabTextStyle</item> 
</style> 

<style name="customActionBarTabStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabView"> 
    <item name="android:background">@color/red</item> 

    <item name="android:textSize">12dp</item> 

</style> 

<style name="customActionBarTabBarStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabBar"> 
    <item name="android:background">@color/red</item> 
</style> 

<style name="customActionBarTabTextStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabText"> 
    <item name="android:titleTextStyle">@style/Theme.Styled.ActionBar.TitleTextStyle</item> 
    <item name="android:textStyle">bold</item> 
</style> 

<style name="Widget.Theme.Styled.ActionBar" parent="Widget.Sherlock.ActionBar"> 
    <item name="android:background">#A9E2F3</item> 
    <item name="background">#A9E2F3</item> 
    <item name="android:titleTextStyle">@style/Theme.Styled.ActionBar.TitleTextStyle</item> 
</style> 

<style name="Theme.Styled.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title"> 
    <item name="android:textColor">@color/red</item> 
    <item name="android:textStyle">bold</item> 
</style> 

<style name="Animations" /> 

答えて

3

使用可能なstyle generatorを使用するか、またはthisthis関連する質問からいくつかのより多くの洞察を得ることができます。

+1

ここで私は、シェリングアクションのスタイリングについていくつか説明しました。http://krishnalalstha.wordpress.com/2012/12/21/styling-sherlock-actionbar-change-actionbar-color/ –

17

もうこれが必要かどうかわかりませんが、私は他の人が見るために回答を投稿します。あなたはDrawableのリソースとして背景customActionBarTabStyleDrawableでこれを設定することができます。

<style name="customActionBarTabStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabView"> 
    <item name="android:background">@drawable/actionbar_tabs_selector</item> 
    <item name="android:textSize">12dp</item> 
</style> 

リソースはセレクタ、これらの行の中で何かをする必要があります:

<!-- This is the "@drawable/actionbar_tabs_selector" layout !--> 

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

    <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_nselected"/> 
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_selected"/> 

    <!-- Pressed state --> 
    <item android:state_pressed="true" android:drawable="@drawable/actionbar_tab_style_selected" /> 

    <!-- Focused state --> 
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_nselected"/> 
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_nselected"/> 

</selector> 

だからここにリソースが2つのレイヤリストです。タブが非アクティブのときの1つと、タブが選択されたときの1つがアクティブです。したがって、選択した状態に応じて2つのレイヤーリストを設定します。

単層リストは次のようになります。

<!-- This is the "@drawable/actionbar_tab_style_nselected" layout !--> 

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

    <!-- Bottom Line --> 
    <item> 
     <shape android:shape="rectangle"> 
      <solid android:color="@color/HCL_orange" /> 
     </shape> 
    </item> 

    <!-- Tab color --> 
    <item android:bottom="2dip"> 
     <shape android:shape="rectangle"> 
      <solid android:color="@android:color/white" /> 
     </shape> 
    </item> 
</layer-list> 

したがって最初のアイテムは、現在選択しているタブのあなたの下線の色として定義することができ、一番下の行で、2番目の項目はの色ですタブ全体。

+0

ニースの答え。 :) –

+2

ありがとうございます。まあ、私はまた、悪いドキュメントのためにAndroidのスタイリングとテーマに挑戦しています。そして、それは本当に残念です... – Tooroop

+0

まさに私が探していた - ありがとう! – martyglaubitz

関連する問題