【发布时间】:2011-01-21 07:37:14
【问题描述】:
我们可以为这样的标签设置背景图片吗?
【问题讨论】:
标签: android background tabs
我们可以为这样的标签设置背景图片吗?
【问题讨论】:
标签: android background tabs
以下代码对我有用:
tabHost.getTabWidget().setBackgroundResource(R.drawable.tabhost_bg);
【讨论】:
试试这个
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);
我使用了默认的 android drawable 你可以使用你想要的
用于设置tabhost的背景
this.mTabHost = (TabHost)this.findViewById(R.id.tabHost);
this.mTabHost.setBackgroundResource(R.drawable.back);
【讨论】: