2012-10-13 7 views
8

私はJake WhartonのViewpagerIndicatorライブラリを使用しています。私は、ActionBarSherlockライブラリと共にタブコードを使用しています。すべて正常に動作しますが、私はタブの背景をスタイルしようとしており、どのように考え出すことができません。 ダークタブとライトフラグメント(タブの内容)を持つ暗いアクションバーが好きですviewpagerindicatorタブのタブ背景を変更するには?

私が使用しているベーステーマは、テーマ。シェロック。ライト。ダークアクションバーです。このスタイルは、タブの属性(テキストの色、インジケータの色など)を設定するスタイルの親にすることで、このスタイルを拡張します。これにより、アクションバー、ライトタブ、およびライトフラグメントが暗くなります。

タブ自体の背景を変更するものは見つかりません。私が変更できる唯一の方法は、アプリケーション全体を暗くすることです(Theme.Sherlockを使用して)。ここに私のコードは、これまでのところです:

<style name="vpiTheme" parent="Theme.Sherlock.Light.DarkActionBar"> 
    <item name="vpiTabPageIndicatorStyle">@style/CustomTabPageIndicator</item> 
</style> 

<style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator"> 
    <item name="android:textColor">#FF000000</item> 
    <item name="android:paddingTop">6dp</item> 
    <item name="android:paddingBottom">6dp</item> 
    <item name="android:paddingLeft">16dip</item> 
    <item name="android:paddingRight">16dip</item> 
    <item name="android:maxLines">2</item> 
</style> 

答えて

0

まず、以下のいずれかがtab_indicator.xmlと呼ばれ、プロジェクトに描画可能なを追加します。

<?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="@android:color/black" /> 
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@android:color/white" /> 
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/black" /> 
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@android:color/white" /> 
</selector> 

を次に、あなたのスタイルであなたの描画可能を参照:

<item name="android:background">@drawable/tab_indicator</item> 

これにより、アクティブなタブは白い背景になり、他のものは黒くなります。

+0

これはカラーインジケータに代わるものでしょうか? – Flyview

+0

はい、そうです。私の目標は指標を取り除くことだったことを忘れてしまった。デフォルトのインジケータ/バックグラウンドは9パッチ画像で行われるので、ここの答えはhttp://stackoverflow.com/questions/10364045/actionbarsherlock-actionbar-custom-background-with-dividerに該当します。 – grant

7

9 - パッチドロワブルはほとんどが透明なので、タブの色は、単にこのように、全体ViewPagerIndicatorに背景色を追加することによって変更することができます。

<com.viewpagerindicator.TabPageIndicator 
    android:id="@+id/indicator" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:background="#333333" /> 

あなたが使用し続けることができますこの方法をテーマはTheme.Sherlock.Light.DarkActionBarに基づいており、新しい描画可能ファイルを作成する必要はありません。

関連する問題