简体   繁体   中英

How to change the background color of the tabs in the action bar?

How do I change the color of the tabs in the action bar of my application.

Tabs:

android标签

Current code to add the tabs:

    private void addTabs(ActionBar actionBar)
{
    ActionBar.Tab tab1=actionBar.newTab();
    tab1.setText("All");
    tab1.setTabListener(this);

    ActionBar.Tab tab2=actionBar.newTab();
    tab2.setText("Technology");
    tab2.setTabListener(this);

    ActionBar.Tab tab3=actionBar.newTab();
    tab3.setText("Business");
    tab3.setTabListener(this);

    actionBar.addTab(tab1);
    actionBar.addTab(tab2);
    actionBar.addTab(tab3);
}

One way to do it is to create a custom theme xml file which is set under the values folder. For example in a theme named Example you could use the following code, if you have a drawable ready, or you could use a colour instead.

<style name="ActionBarTabStyle.Example" parent="@android:style/Widget.Holo.ActionBar.TabView"> <item name="android:background">@drawable/tab_indicator_ab_example</item> </style>

I'd recommend visiting Android Action Bar Style Generator as it makes styling your action bar and tabs really easy and saves you some time.

Don't forget to change the theme under your android manifest xml file.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM