Can we set a background image to tabs?

17,876

Solution 1

Following code worked for me:

 tabHost.getTabWidget().setBackgroundResource(R.drawable.tabhost_bg);

Solution 2

try this

             getTabHost().addTab(getTabHost().newTabSpec("A")
                    //set the tab name
                    .setIndicator("A")
                    //Add additional flags to the intent (or with existing flags value).
                    .setContent(new Intent(this, A.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));      

            //for creating tab we need to pass tabSpec and tab name to setIndicator and pass intent to its 
                //setContent  to Tab Activity predefined method getTabHost then it will create tab
             getTabHost().addTab(getTabHost().newTabSpec("B")
                    //set the tab name
                        .setIndicator("B")

                         //Add additional flags to the intent (or with existing flags value).
                       .setContent(new Intent(this,B.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) );

getTabHost().addTab(getTabHost().newTabSpec("C")
                    //set the tab name
                        .setIndicator("C")

                         //Add additional flags to the intent (or with existing flags value).
                       .setContent(new Intent(this,C.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) );    


             getTabHost().getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.a);
 getTabHost().getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.b);
 getTabHost().getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.c);

Solution 3

TabSpec generalTab = mTabHost.newTabSpec("general");
generalTab.setIndicator("General", getResources().getDrawable(android.R.drawable.ic_menu_preferences)).setContent(R.id.tabGeneral);

I have used default android drawable u can use what you want

for setting background of tabhost

this.mTabHost = (TabHost)this.findViewById(R.id.tabHost);
    this.mTabHost.setBackgroundResource(R.drawable.back);
Share:
17,876

Related videos on Youtube

neha
Author by

neha

Updated on June 04, 2022

Comments

  • neha
    neha almost 2 years

    Can we set a background image to tabs like this?

    alt text

  • neha
    neha over 13 years
    This will set image as background to individual tabs. I want to set background image to background of all the tabs [part below the tabs].
  • neha
    neha over 13 years
    This' setting the background image to entire screen and not just background of tabs.
  • ingsaurabh
    ingsaurabh over 13 years
    actually what you wanted is done in this way only it will set the image to whole background but when you put different images in different tabs then this image is hided by tabs image this is the only workaround I know hope any other can have better answer for this
  • Farhan
    Farhan about 13 years
    in the picture tabs seems to be transparent... how did you do this? I manage to set background but my tabs are visible on top with grey colour... :(
  • ernazm
    ernazm over 12 years
    You need to set view with transparent background (or w/o any) as an indicator to your tabs to make this solution work.

Related