android > tabHost > 微博布局风格
tab.xml 布局
?
tab_list.xml
?
?
主activity
package tab.mft;import cfg.mft.CfgIndex;import login.mft.LoginAddSensor;import login.mft.LoginIndexActivity;import remote2.mft.R;import android.app.TabActivity;import android.content.Intent;import android.graphics.Color;import android.os.Bundle;import android.view.View;import android.widget.ImageView;import android.widget.TabHost;import android.widget.TabHost.OnTabChangeListener;import android.widget.TextView;public class TabIndex extends TabActivity{private TabHost tabHost; private static final String SYS = "系统"; private static final String SERVERS = "服务"; private static final String MORE = "更多"; @Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.tab);tabHost=getTabHost();final View view=View.inflate(TabIndex.this, R.layout.tab_list, null);view.setBackgroundColor(Color.rgb(33,36,41)); //默认第一个点亮((ImageView)view.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_home_sel); //默认第一个点亮((TextView)view.findViewById(R.id.tab_textview_title)).setText(SYS); TabHost.TabSpec tabSpec=tabHost.newTabSpec(SYS).setIndicator(view).setContent(new Intent(TabIndex.this, LoginIndexActivity.class));tabHost.addTab(tabSpec);final View view1=View.inflate(TabIndex.this, R.layout.tab_list, null);((ImageView)view1.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_selfinfo_nor);((TextView)view1.findViewById(R.id.tab_textview_title)).setText(SERVERS); TabHost.TabSpec tabSpec1=tabHost.newTabSpec(SERVERS).setIndicator(view1).setContent(new Intent(TabIndex.this, LoginAddSensor.class));tabHost.addTab(tabSpec1);final View view2=View.inflate(TabIndex.this, R.layout.tab_list, null);((ImageView)view2.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_more_nor);((TextView)view2.findViewById(R.id.tab_textview_title)).setText(MORE); TabHost.TabSpec tabSpec2=tabHost.newTabSpec(MORE).setIndicator(view2).setContent(new Intent(TabIndex.this, LoginAddSensor.class));tabHost.addTab(tabSpec2);tabHost.setCurrentTab(0);//设置切换监听tabHost.setOnTabChangedListener(new OnTabChangeListener(){public void onTabChanged(String tabId){((ImageView)view.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_home_nor);view.setBackgroundColor(Color.rgb(57,60,66));((ImageView)view1.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_selfinfo_nor);view1.setBackgroundColor(Color.rgb(57,60,66));((ImageView)view2.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_more_nor);view2.setBackgroundColor(Color.rgb(57,60,66));if(tabId.equals(SYS)){((ImageView)view.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_home_sel);view.setBackgroundColor(Color.rgb(33,36,41));}if(tabId.equals(SERVERS)){((ImageView)view1.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_selfinfo_sel);view1.setBackgroundColor(Color.rgb(33,36,41));}if(tabId.equals(MORE)){((ImageView)view2.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_more_sel);view2.setBackgroundColor(Color.rgb(33,36,41));}}});}}?