astuetz / PagerSlidingTabStrip

An interactive indicator to navigate between the different pages of a ViewPager
139 stars 44 forks source link

how to change tab background color #123

Open abc2005 opened 10 years ago

abc2005 commented 10 years ago

HI thanks you for this perfect tab. I just wanted to know how can I change tab background color ? I tried to change it from xml but it didn't work . Could you help me ?

thanks you

TequilaZhang commented 10 years ago

me too

ChrisMCMine commented 10 years ago

tabs.setBackgroundColor(Color.BLACK);

vandus commented 10 years ago

If you want to keep the bottom indicator, you define the main color of the tab directly in the layout, like in this example: <com.astuetz.PagerSlidingTabStrip android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="48dip" app:pstsShouldExpand="true" app:pstsIndicatorColor="@color/turquoise" android:background="@android:color/white" />

So my main color is white and the indicator color is turqoise. If you want to change the DrawableStateList for pressed and focused states, always keep transparent as the default color, and pick any color for your desired states.

alaouiali commented 9 years ago

Thanks vandus ! I confirm: "...always keep transparent as the default color, and pick any color for your desired states."

Logan676 commented 9 years ago

in order to keep the indicator, you should set the code like below

PagerSlidingTabStrip:pstsTabBackground="@drawable/tab_bg_selector"
android:background="@color/fancy_white"

the selector is

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/theme_color"/>
    <item android:state_selected="true" android:drawable="@color/theme_color"/>
    <item android:drawable="@color/transparent"/>
</selector>

delete the pstsUnderlineColor attr if you have set, otherwise the indicator won`t shown.