TabActivity的使用遇到的问题
16lz
2021-12-04
private TabHost tabHost;@Overrideprotected 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)); } } }@Overridepublic 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
更多相关文章
- Android边框背景
- Android(安卓)开源源代码收集(不断更新中...)
- Android(安卓)ListView(Selector 颜色)
- ApacheCN 网络安全译文集 20211025 更新
- android 量产软件改动信息(持续更新)
- Android学好Shape不再依赖美工
- Android的线程使用来更新UI----Thread、Handler、Looper、TimerT
- [android]浅谈android的selector,背景选择器
- 应用界面主题Theme使用方法