我已经创建了一个标签主机..我想要做的是改变每个选项卡上的主机的背景颜色..在我的情况下使用三个标签主机intially背景颜色我的第一个标签是白色和休息两个是黑色的...现在我想要的是当我点击我的第二个选项卡时,它的背景颜色会变成白色,其余两个会变成黑色等等..我正在发送我的代码。让任何人检查我所在的位置要做到这一点..问题在标签主机
public void createTabHost()
{
//create tabs
Resources res = getResources();
TabHost MainTabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
if(7 < Build.VERSION.SDK_INT)
{
MainTabHost.getTabWidget().setStripEnabled(false);
}
//call calendar Activity class
intent = new Intent().setClass(this, CalendarForm.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
spec = MainTabHost.newTabSpec("Calendar").setIndicator("Calendar",
res.getDrawable(R.drawable.calendar_ic)).setContent(intent);
MainTabHost.addTab(spec);
//call History Activity class
intent = new Intent().setClass(this, HistoryForm.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
spec = MainTabHost.newTabSpec("History").setIndicator("History",
res.getDrawable(R.drawable.calendar_ic)).setContent(intent);
MainTabHost.addTab(spec);
//call Statistic Activity class
intent = new Intent().setClass(this, StatisticForm.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
spec = MainTabHost.newTabSpec("Statistic").setIndicator("Statistic",
res.getDrawable(R.drawable.calendar_ic)).setContent(intent);
MainTabHost.addTab(spec);
//setbackground Style of tabHost
MainTabHost.setCurrentTab(0);
MainTabHost.getTabWidget().setWeightSum(3);
TabWidget tabHost=getTabWidget();
MainTabHost.setBackgroundColor(Color.parseColor("#E0DCC9"));
//MainTabHost.setBackgroundResource(R.drawable.back_img);
for (int j = 0; j < MainTabHost.getTabWidget().getChildCount(); j++)
{
((TextView)tabHost.getChildAt(j).findViewById(android.R.id.title)).setTextColor(Color.parseColor("#FFFFFF"));
MainTabHost.getTabWidget().getChildAt(j).setBackgroundColor(Color.parseColor("#000000"));
}
MainTabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#E0DCC9"));
((TextView)tabHost.getChildAt(0).findViewById(android.R.id.title)).setTextColor(Color.parseColor("#000000"));
}
我试过了,但它并没有覆盖整个标签......意味着它设置了免费但是只有一半的标签......将发送你的快照 – AndroidDev
我给你发了快照..只是检查它 – AndroidDev
嗯让我5分钟检查一下;) – Atheh