标签:
Refer to :http://android.toolib.net/reference/android/widget/TabHost.html
tabHost=(TabHost)findViewById(android.R.id.tabhost);????//获取TabHost对象 tabHost.setup();????//初始化TabHost组件 LayoutInflater inflater = LayoutInflater.from(this); ????// 声明并实例化一个LayoutInflater对象 //Begin to add more tab. inflater.inflate(R.layout.tab1, tabHost.getTabContentView()); inflater.inflate(R.layout.tab2, tabHost.getTabContentView()); inflater.inflate(R.layout.tab3, tabHost.getTabContentView()); inflater.inflate(R.layout.tab7, tabHost.getTabContentView()); //inflater.inflate(R.layout.tab4, tabHost.getTabContentView()); ? ? tabHost.addTab(tabHost.newTabSpec("tab01") ????????.setIndicator("SET") ????????.setContent(R.id.LinearLayout01)); //添加第一个标签页 tabHost.addTab(tabHost.newTabSpec("tab02") ????????.setIndicator("VID6X") ????????.setContent(R.id.LinearLayout02)); ????//添加第二个标签页 tabHost.addTab(tabHost.newTabSpec("tab03") ????????.setIndicator("VID2X-7X") ????????.setContent(R.id.LinearLayout03)); tabHost.addTab(tabHost.newTabSpec("tab04") ????????.setIndicator("CCD-TEST") ????????.setContent(R.id.LinearLayout07)); ? //tabHost.addTab(tabHost.newTabSpec("tab04") //????????.setIndicator("DASHBOARD") // ????????.setContent(R.id.LinearLayout04)); /*选项卡标题高度*/ /* tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 75; tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 75; tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 75; tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 75; */ |
切换选项卡事件:
/*当从VID6X或2X-7X选项卡中切换到其它选项卡时执行*/ ????????tabHost.setOnTabChangedListener(new OnTabChangeListener(){ ????????????@Override ????????????public void onTabChanged(String tabId) { ????????????????// TODO Auto-generated method stub ????????????????if((at6xdemo_flag==1)&&(!tabId.equals("tab02"))){ ????????????????????at6xdemo_flag=0; ????????????????????Toast.makeText(getApplicationContext(), "shut down 6x_demo", Toast.LENGTH_SHORT).show(); ????????????????} ????????????????if((at27xdemo_flag==1)&&(!tabId.equals("tab03"))){ ????????????????????at27xdemo_flag=0; ????????????????????Toast.makeText(getApplicationContext(), "shut down 2x7x_demo", Toast.LENGTH_SHORT).show(); ????????????????????demostart_flag=0; ????????????????????TextView text=(TextView)findViewById(R.id.startText); ????????????????????text.setText("start"); ????????????????????Button start2 =(Button) findViewById(R.id.start); ????????????????????start2.setBackgroundResource(R.drawable.stoppi); ????????????????} ????????????}???? ????????}); |
标签:
原文地址:http://www.cnblogs.com/zhlforhe/p/4794989.html