码迷,mamicode.com
首页 > 其他好文 > 详细

TabHost 选项卡

时间:2015-09-09 16:25:54      阅读:183      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!