Android tab 背景及字体颜色设置

 

final TabHost host = getTabHost();
final TabWidget tabWidget=host.getTabWidget();
host.setOnTabChangedListener(new OnTabChangeListener() {
	@Override
	public void onTabChanged(String tabId) {
		for (int i =0; i < tabWidget.getChildCount(); i++) {
		    LinearLayout view = (LinearLayout) tabWidget.getChildAt(i);
			if(host.getCurrentTab()==i){
				view.setBackgroundResource(R.drawable.bookmark_tab_click);
				final TextView tv = (TextView) view.getChildAt(0);
				tv.setTextColor(getResources().getColor(R.color.rank_click_color));
			} else {
				view.setBackgroundResource(R.drawable.bookmark_tab_primitive);
			        final TextView tv = (TextView) view.getChildAt(0);
			        tv.setTextColor(getResources().getColorStateList(android.R.color.white));
		        }
		}
	}
});

 

 

你可能感兴趣的:(android)