Can we set a background image to tabs?
Can we set a background image to tabs like th开发者_开发问答is?
Following code worked for me:
tabHost.getTabWidget().setBackgroundResource(R.drawable.tabhost_bg);
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);
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);
精彩评论