2012-09-13 9 views
24

私のレイアウトはViewPagerです。テキストの下にある現在のタブハイライターの色を変更したいと思います。実際には黒色で表示されています。しかし、色がデフォルトであるかどうかは分かりません。また、もう一つの疑問がある。 PagerTitleStripを使用すると、このタブのハイライターは表示されません。それを持っていく方法はありますか?これはちょうど働くAndroid ViewPagerで現在のタブハイライターの色を変更するにはどうすればよいですか?

<android.support.v4.view.PagerTabStrip android:id="@+id/pager_title_strip" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="top" 
    android:background="@color/pager_titlestrip_bg"  
    android:textColor="@color/pager_titlestrip_text" 
    android:paddingTop="5dp" 
    android:paddingBottom="4dp" > 
    </android.support.v4.view.PagerTabStrip> 
+0

私はJakeWharton ViewPagerインジケータソリューションを調べました。私にとっては、スワイプのタブはうまく機能します。しかし、私はタブインジケータの色を変更したい。タブのテキストを変更するオプションがあります。しかし、インジケータの色ではありません。デフォルトでは黒色で表示されています。 – intrepidkarthi

答えて

60

は、ここに私のレイアウトです。

PagerTabStrip pagerTabStrip = (PagerTabStrip) findViewById(R.id.pager_title_strip); 
pagerTabStrip.setDrawFullUnderline(true); 
pagerTabStrip.setTabIndicatorColor(Color.RED); 

ありがとう!

11

単にあなたがこのコードを解決することができるXML

<android.support.design.widget.TabLayout 
     android:id="@+id/tabanim_tabs" 
     android:layout_width="match_parent" 
     app:tabIndicatorHeight="4dp" 
     app:tabIndicatorColor="@android:color/white" 
     android:layout_height="wrap_content" /> 

以上のことにより、JavaまたはXML

と、プログラムの両方で行うことができますは、高さを変更するには同様に

tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FFFFFF")); 

をaswell

tabLayout.setSelectedTabIndicatorHeight((int) (2 * getResources().getDisplayMetrics().density)); 
+0

それは私の問題を解決した... :) – Sangharsha

0

これは私のプロジェクトで動作します。

<android.support.design.widget.TabLayout 
    android:id="@+id/tabs" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#FFF" 
    app:tabGravity="fill" 
    app:tabIndicatorColor="@color/text3" 
    app:tabMode="scrollable" 
    app:tabSelectedTextColor="@color/text3" 
    app:tabTextColor="#000" /> 
関連する問題