for (int i = 0; i < tabWidget.getChildCount(); i++) {
/**
* 此方法是爲了去掉系統默認的色白的底角 在 TabWidget中mBottomLeftStrip、mBottomRightStrip
* 都是私有變量,但是我們可以通過反射來獲取 由於還不知道Android 2.2的接口是怎麼樣的,現在先加個判斷好一些
*/
if (Integer.parseInt(Build.VERSION.SDK) <= 5)
{
}
else
{
// 貌似也可以去掉系統默認的色白的底角
Constant.tabHost.setPadding(Constant.tabHost.getPaddingLeft(),
Constant.tabHost.getPaddingTop(), Constant.tabHost
.getPaddingRight(), Constant.tabHost
.getPaddingBottom()-1 );//原文是-5,我這邊試了一下,-1最好。
}
View v = tabWidget.getChildAt(i);
// 設置tab背景顏色
v.setBackgroundResource(R.drawable.tab_indicator);
// 設置tab中標題文字的顏色,不然默認爲黑色
XmlResourceParser xpp = getResources().getXml(
R.color.tab_font_selector);
try
{
ColorStateList csl = ColorStateList.createFromXml(
getResources(), xpp);
TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(
android.R.id.title);
tv.setTextColor(csl);
}
catch (Exception e)
{
}
}