-1

This is already being implemented in Google Play and I want to use it in my app. I've implemented the sliding tabs and toolbar using the android design library. My application features 4 tabs and I want to achieve this kind of color change among these tabs. Here are the screenshots of the Google Play app which I was referring to.

First Tab

enter image description here

Second Tab

enter image description here

Third Tab - same root as above links with the extension /Mc3a7.png (Apologies for this, but I'm not able to post more than 2 links due to a low reputation.)

Please note that a solution which is being implemented in JAVA will be preferred by me over one which suggests using XML for this purpose :)

Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
  • https://github.com/astuetz/PagerSlidingTabStrip/blob/master/sample/src/com/astuetz/viewpager/extensions/sample/MainActivity.java – Gowthaman M Oct 07 '17 at 11:40
  • 1
    Possible duplicate of [How do I change a tab background color when using TabLayout?](https://stackoverflow.com/questions/31640563/how-do-i-change-a-tab-background-color-when-using-tablayout) – Dima Kozhevin Oct 07 '17 at 11:47

1 Answers1

0

if your are using view-pager you can set listener on it and then change toolbar color

 mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            switch (position) {
                case 0:
                    toolbar.setBackgroundColor(Color.YELLOW);
                    break;
                case 1:
                    toolbar.setBackgroundColor(Color.GREEN);
                    break;
                case 2:
                    toolbar.setBackgroundColor(Color.RED);
                    break;
                default:
                    break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
Hamid Reza
  • 624
  • 7
  • 23