clever_trevor
clever_trevor

Reputation: 1674

Change ViewPager Indicator color

I am trying to change the color of my ViewPager Indicator. I've read on here that it uses a nine-patch, but I do not know where to find it. Here is my relevant Java code for the ViewPager creation.

/**
 * On swiping the ViewPager make respective tab selected
 **/
private void initializeViewPagerListener() {
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            // on changing the page
            // make respected tab selected
            actionBar.setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}

/**
 * Creates the tab portion of the ViewPager
 */
private void initializeTabs() {
    viewPager = (ViewPager) findViewById(R.id.pager);
    actionBar = getActionBar();
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

    viewPager.setAdapter(mAdapter);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);


    // Adding Tabs
    for (String tab_name : tabs) {
        actionBar.addTab(actionBar.newTab().setText(tab_name)
                .setTabListener(this));
    }

}

Upvotes: 0

Views: 11341

Answers (5)

Madi
Madi

Reputation: 1855

Write this line on your java class indicator.setFillColor(Color.RED);

Upvotes: 0

bambi
bambi

Reputation: 33

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

Upvotes: 0

nima72
nima72

Reputation: 36

from the ViewPagerIndicator document from the below link:

AndroidViewPagerIndicator

you can set this: Add the custom view below your view pager, the available attributes are: radius that specifies the radius of the circles and color to specify the color of them

<com.efoad.views.ViewPagerIndicator
android:id="@+id/viewpager_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:padding="5dp"
custom:radius="3dp"
custom:color="@android:color/darker_gray" />

Upvotes: 0

bigsolom
bigsolom

Reputation: 2349

I've created a custom ViewPager Indicator (nexus-5 launcher style) with custom attribute available to change the circles color

https://github.com/bigsolom/AndroidViewPagerIndicator

Upvotes: 0

mako
mako

Reputation: 1

Which ViewPager are you using? From support library or from which Android version?

If it is android.support.v4.view.ViewPager you should only add one line of code:

    viewPager.getChildAt(0).setBackgroundResource(R.color.blue);

And also define blue color(or any other color chosen by you) in res/values/color.xml file:

    <color name="blue">#015599</color>

This should help.

Upvotes: -1

Related Questions