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));
		        }
		}
	}
});

猜你喜欢

转载自yeruowei.iteye.com/blog/1779296
今日推荐