android tabhost改变标签高度和背景颜色

来源:互联网 发布:第二号码软件 编辑:程序博客网 时间:2024/05/16 14:25
myTabhost.getTabWidget().getChildAt(0).getLayoutParams().height = 75; //设置标题高度myTabhost.getTabWidget().getChildAt(1).getLayoutParams().height =75; 
 
// 初始化设置一次标签背景         updateTabBackground(myTabhost);         // 选择时背景更改。         myTabhost.setOnTabChangedListener(new OnTabChangeListener() {             @ Override             public void onTabChanged(String tabId) {                 updateTabBackground(myTabhost);             }  /**      * 更新Tab标签的背景图      *      * @param tabHost      */     private void updateTabBackground(final TabHost tabHost) {         for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {             View vvv = tabHost.getTabWidget().getChildAt(i);             if (tabHost.getCurrentTab() == i) {                 // 选中后的背景                 vvv.setBackgroundDrawable(getResources().getDrawable(                                               R.drawable.blue));             } else {                 // 非选择的背景                 vvv.setBackgroundDrawable(getResources().getDrawable(                                               R.drawable.lightblue));             }         }     } 



	
				
		
原创粉丝点击