Aditi K
Aditi K

Reputation: 1554

How to change selected Tab background color programatically or using xml in ActionbarTab?

how to change specific tab color change on select event of Actionbar Tab i am using Actionbar Tab with view Pager tabs created programatically

Upvotes: 2

Views: 7998

Answers (2)

Nick Cardoso
Nick Cardoso

Reputation: 21753

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);

Upvotes: 1

Radheshyam Singh
Radheshyam Singh

Reputation: 479

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);
  }
 });

Upvotes: 1

Related Questions