private TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO 需要设计该Tab的UI布局
super.onCreate(savedInstanceState);
tabHost = this.getTabHost();
LayoutInflater.from(this).inflate(R.layout.al_inpatient_detail, tabHost.getTabContentView(), true);
tabHost.setBackgroundResource(R.drawable.bg_main);
// 住院诊断
tabHost.addTab(
tabHost.newTabSpec("One")
.setIndicator(Constant.CENTER_INPATIENT_DIAGOSIS, getResources().getDrawable(R.drawable.center_inpatient_diagosis))
.setContent(R.id.linear_diagnosis)
);
// 费用明细
tabHost.addTab(
tabHost.newTabSpec("Two")
.setIndicator(Constant.CENTER_INPATIENT_COST, getResources().getDrawable(R.drawable.center_inpatient_cost))
.setContent(R.id.linear_cost)
);
// 结算明细
tabHost.addTab(
tabHost.newTabSpec("Three")
.setIndicator(Constant.CENTER_INPATIENT_CLEARING_FEE, getResources().getDrawable(R.drawable.center_inpatient_clearing_fee))
.setContent(R.id.linear_clearing_fee)
);
// TODO 字体颜色
TabWidget tabWidget = tabHost.getTabWidget();
for (int i =0; i < tabWidget.getChildCount(); i++) {
tabWidget.setBackgroundColor(Color.WHITE);
// tabWidget.getChildAt(i).getLayoutParams().height = 30;//设置tab的高度
TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
tv.setTextColor(Color.BLUE);//设置tab内字体的颜色
}
// 点击更新背景
tabHost.setOnTabChangedListener(this);
tabHost.setCurrentTab(2);
// TODO 查询数据,填充UI
}
/**
* 更新Tab标签的背景图
* @param tabHost
*/
private void updateTabBackground( TabHost tabHost) {
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
View view = tabHost.getTabWidget().getChildAt(i);
if (tabHost.getCurrentTab() == i) {
//选中后的背景
view.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_press_click));
} else {
//非选择的背景
view.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_main));
}
}
}
@Override
public void onTabChanged(String tabId) {
// 点击更新背景
updateTabBackground(tabHost);
}
参考:http://www.eoeandroid.com/thread-56303-1-1.html
参考:http://www.cnblogs.com/xitang/archive/2011/09/14/2176539.html