我已經創建了一個標籤主機..我想要做的是改變每個選項卡上的主機的背景顏色..在我的情況下使用三個標籤主機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