user782104
user782104

Reputation: 13545

How to change the background of the tabhost

I have a tabhost with ~ 5 tabs,and I would like to change the background of it . There is a background image of the tabs , one rectangle image of all tabs. When I add to tabhost . It does not work. How to fix it? Thanks

   <android.support.v4.app.FragmentTabHost
        android:id="@+id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:orientation="horizontal"
        android:background="@drawable/tabBg"
   /> 

Upvotes: 1

Views: 279

Answers (3)

user2754122
user2754122

Reputation:

Do like this...

tabhost
 .getTabWidget()
 .getChildAt(/*Index of the tab of which you want to change the background*/)
 .setBackground(/*the background res you want to set */)

Upvotes: 1

user782104
user782104

Reputation: 13545

Finally got the solution

public void setTabColor(TabHost tabhost) {
        for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
        {
             tabhost.getTabWidget().getChildAt(i).setBackground(res.getDrawable(R.drawable.share_tab_bg)); // selected
        }
    }

Upvotes: 0

user3211432
user3211432

Reputation: 11

Try this

spec = tabHost.newTabSpec("orders")
       .setIndicator("Orders",res.getDrawable(R.drawable.flash_36))
       .setContent(R.id.ordersLayout);

Upvotes: 0

Related Questions