Simple changing colors tabs.
Add colors to res.arrays. Each array corresponds to tab. First item is ActionBar color, second - StatusBar color, third - TabIndicator color and the last one is background color.
<array name="color_set_tab_1">
<item>#9C27B0</item>
<item>#6A1B9A</item>
<item>#69F0AE</item>
<item>#E1BEE7</item>
</array>
Obtain color arrays via getResources().obtainTypedArray() to an array of TypedArray.
TypedArray[] colors = new TypedArray[]{
resources.obtainTypedArray(R.array.color_set_tab_1),
resources.obtainTypedArray(R.array.color_set_tab_2),
resources.obtainTypedArray(R.array.color_set_tab_3)};
Get TabLayout and ViewPager instances.
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
Create an instance of ColorChangeListener and provide it TypedArray[], Window and TabLayout.
ColorChangeListener listener = new ColorChangeListener(colors, getWindow(), tabLayout);
Attach that listener to ViewPager.
viewPager.addOnPageChangeListener(listener);
Setup TabLayout with ViewPager.
tabLayout.setupWithViewPager(viewPager);