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);
Related videos on Youtube
Author by
neha
Updated on June 04, 2022Comments
-
neha almost 2 years
Can we set a background image to tabs like this?
-
neha over 13 yearsThis 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 over 13 yearsThis' setting the background image to entire screen and not just background of tabs.
-
ingsaurabh over 13 yearsactually 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 about 13 yearsin 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 over 12 yearsYou need to set view with transparent background (or w/o any) as an indicator to your tabs to make this solution work.