Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add style to PagerTabStrip of Viewpager in Android

I'm working with Android ViewPager in three views. I added a android.support.v4.view.PagerTabStrip to display the title of each view.

Current appearance enter image description here

Desired appearance

enter image description here

How I can get this result?

Regards!

like image 963
Adrián Avatar asked Nov 10 '22 10:11

Adrián


1 Answers

I customize my PagerTabStrip by customizing AppThemes in the styles.xml, the code below is how I do it in my apps.

<style name="_AppTheme" parent="android:Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/mActionBar</item>
    <item name="android:actionMenuTextColor">#FFFFFF</item>
    <item name="android:actionBarTabTextStyle">@style/ActionBarTextStyle</item>
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle</item>
    <item name="android:windowContentOverlay">@null</item>
</style> 

<style name="ActionBarTextStyle" parent="AppBaseTheme">
        <item name="android:textColor">#FF8800</item>
        <item name="android:drawablePadding">10dp</item>
        <item name="android:paddingLeft">10dp</item>
        <item name="android:paddingRight">10dp</item>
    </style>

<style name="ActionBarTabStyle" parent="@style/Widget.AppCompat.Light.ActionBar.TabView">
    <item name="android:background">@drawable/tab_indicator_ab_example</item>
    <item name="android:drawablePadding">10dp</item>
</style>


<style name="mActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">#FF8800</item>
        <item name="android:icon">@android:color/transparent</item>
        <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    </style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:drawablePadding">10dp</item>
    <item name="android:paddingLeft">10dp</item>
    <item name="android:paddingRight">10dp</item>
</style>

Hope it helps you. =)

like image 156
Daniel tan Avatar answered Nov 15 '22 01:11

Daniel tan