TabHost标题图片变换例子

 

好久没上了,今天弄个小例子,关于标题图片变化的例子,直接上例子。


	tabHost.setOnTabChangedListener(new OnTabChangeListener() {
			@Override
			public void onTabChanged(String tabId) {
				
				if(tabId.equals("tab1")){
					//getChildAt(i),里面的i表示对应的tab。
					ImageView iv = (ImageView) getTabWidget().getChildAt(0).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.basicinfo2));
					iv = (ImageView) getTabWidget().getChildAt(1).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.dise1));
					iv = (ImageView) getTabWidget().getChildAt(2).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.manage1));
					iv = (ImageView) getTabWidget().getChildAt(3).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.service1));
				}else if(tabId.equals("tab2")){
					ImageView iv = (ImageView) getTabWidget().getChildAt(0).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.basicinfo1));
					iv = (ImageView) getTabWidget().getChildAt(1).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.dise2));
					iv = (ImageView) getTabWidget().getChildAt(2).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.manage1));
					iv = (ImageView) getTabWidget().getChildAt(3).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.service1));
				}else if(tabId.equals("tab3")){
					ImageView iv = (ImageView) getTabWidget().getChildAt(0).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.basicinfo1));
					iv = (ImageView) getTabWidget().getChildAt(1).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.dise1));
					iv = (ImageView) getTabWidget().getChildAt(2).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.manage2));
					iv = (ImageView) getTabWidget().getChildAt(3).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.service1));
				}else if(tabId.equals("tab4")){
					ImageView iv = (ImageView) getTabWidget().getChildAt(0).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.basicinfo1));
					iv = (ImageView) getTabWidget().getChildAt(1).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.dise1));
					iv = (ImageView) getTabWidget().getChildAt(2).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.manage1));
					iv = (ImageView) getTabWidget().getChildAt(3).findViewById(android.R.id.icon);
					iv.setImageDrawable(getResources().getDrawable(R.drawable.service2));
				}
			}
	});

 

 

 

下面看下效果:

TabHost标题图片变换例子

你可能感兴趣的:(android)