I am trying to change the color of the action bar tabs programmatically. I have the default in styles.xml as red, since I want them to be with different tabs in my view, however on the first tab I want the action bar and navigation tabs to become transparent. I did this using the action bar using this code
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
int newActionBarColor;
if(tab.getPosition() == 0) {
newActionBarColor = Color.parseColor("#" + Integer.toHexString(getResources().getColor(R.color.actionBarTransparent)));
} else {
newActionBarColor = Color.parseColor("#" + Integer.toHexString(getResources().getColor(R.color.actionBar)));
}
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(newActionBarColor));
mViewPager.setCurrentItem(tab.getPosition());
}
But I can not get this to work with tabs, any ideas? You can see what I tried above.
The activity on the tab where I want the color tabs:

What am I on the tab now, where I want the action bar and tab to be transparent:

source
share