how to change specific tab color change on select event of Actionbar Tab i am using Actionbar Tab with view Pager tabs created programatically
Asked
Active
Viewed 7,988 times
2 Answers
1
in styles.xml
<style name="AppTheme" parent="android:Theme.Holo">
<item name="android:actionBarTabStyle">@style/MyTabStyle</item>
</style>
<style name="MyTabStyle" parent="android:Widget.ActionBar.TabView">
<item name="android:background">@drawable/my_drawable</item>
</style>
or in code:
TextView v = new TextView(...);
v.setBackground(R.drawable.my_bg);
ActionBar bar = getActionBar();
ActionBar.Tab tab = bar.getTabAt(position);
tab.setCustomView(v);

Nick Cardoso
- 20,807
- 14
- 73
- 124
-
-
You make your drawable use a selector (if you are just trying to make the selected tab another colour?) – Nick Cardoso Jan 28 '14 at 13:18
-
please read my question again i want to change color for Selected tab of actionbar TAB not the actionBar – Aditi K Jan 28 '14 at 13:25
-
both methods *are* the tab, but your right, i put the wrong code on a line, I've fixed it now – Nick Cardoso Jan 28 '14 at 13:32
-
plz check out question posted by me [Link](http://stackoverflow.com/questions/21402936/how-to-show-action-bar-tabs-on-different-line) – Aditi K Jan 28 '14 at 13:34
-
If you wanted me to answer it, I'm sorry but I have no idea what causes the other issue. – Nick Cardoso Jan 28 '14 at 13:44
1
to programatically change the tab's background color
myTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener(){
@Override
public void onTabChanged(String tabId) {
int tab = myTabHost.getCurrentTab();
View view = myTabHost.getTabWidget().getChildAt(tab).setBackgroundColor(Color.CYAN);
}
});

Radheshyam Singh
- 479
- 3
- 10
-
-
i used vp.getChildAt(tab.getPosition()).setBackgroundColor(Color.GREEN); but not working properly – Aditi K Jan 28 '14 at 13:35
-
if you are using the color code then don't forget to parse the color code Ex. tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#8A4117")); – Radheshyam Singh Jan 28 '14 at 13:44