首页 > 其他 > 详细

TabHost 选项卡

时间:2015-09-09 17:24:56      阅读:266      评论:0      收藏:0      [点我收藏+]

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; */

切换选项卡事件:

/*当从VID6X2X-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);

????????????????}

????????????}????

????????});

TabHost 选项卡

原文:http://www.cnblogs.com/zhlforhe/p/4794989.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!