9

Is it possible to change color of selected tab on v4 ViewPager?
I need to use v4 ViewPager, but I don't find any source to customize it.
Just to clarify I need to change the blue color to another one:

TabSelector

Tizianoreica
  • 2,142
  • 3
  • 28
  • 43
  • have u checked this http://stackoverflow.com/questions/12408080/how-to-change-the-current-tab-highlighter-color-in-android-viewpager – TheFlash Aug 06 '13 at 10:27

4 Answers4

11

This is the tab indicator. You can change its color by applying different styles.

Use Action Bar Style Generator, generate 9patch png files (tab_selected, tab_selected_focused etc.) and add these files + styles to your project.

Another approach -> How to change the current tab highlighter color in Android ViewPager? (as @Pratik wrote in comment).

Community
  • 1
  • 1
mmBs
  • 8,421
  • 6
  • 38
  • 46
  • 1
    it does not work at all. I am using tab swipe WITH FRAGMENT ACTIVITY – Jeff Bootsholz Jun 15 '14 at 04:18
  • 1
    Please refer to esme_louise's answer. I was having trouble too but his clue saved my problem. I suppose it solve yours as well. – Fatima Sep 20 '14 at 10:36
  • 1
    And you might also make sure you have chosen the right option in "style compatibility". By default it is Holo and if yu are using Appcompat or Sherlok it will not work properly. – Fatima Sep 21 '14 at 10:13
3

I don't have enough reputation to comment on an Answer, but regarding the Action Bar Style Generator make sure after you add the files to the corresponding folders in your project that you also add the theme to your manifest xml file like this:

<activity
    android:name="com.whatever.myapplication.YourActivityName"
    android:theme="@style/Theme.Whatever_you_named_your_style_in_the_generator">
</activity>
esme_louise
  • 540
  • 2
  • 9
  • 28
  • 1
    For future visitors: In manifest you may need to set the whole app theme (not just an activity). like this: – Fatima Sep 21 '14 at 10:10
2

The ViewPager is not the one you need to customize. You need to set the tabIndicatorColor of the TabLayout linked with it in the layout.

Dynamically you could do

TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout_id);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setSelectedTabIndicatorColor(R.color.your_color); // here

Inside the XML, that would be as simple as the following

<android.support.design.widget.TabLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabIndicatorColor="@color/your_color" />
oldergod
  • 15,033
  • 7
  • 62
  • 88
0

Same way i don't find the way to customize the tab. So i have fixed it using

<View
        android:layout_height="2dp"
        android:id="@+id/line1"
         android:layout_width="fill_parent"
        android:layout_below="@+id/headertab1"
       android:layout_above="@+id/viewpager"
        android:background="#0066CC" />

I have put this code with each 3 tabs belove the tab & above viewPager. As we can detect that which tab is selected very easily. So we can use this 'line1' visibility to View.VISIBLE or View.INVISIBLE.

Hope it helps to you!!

Bhoomika Brahmbhatt
  • 7,404
  • 3
  • 29
  • 44