TabHost是整个Tab的容器,包括两部分,TabWidget和FrameLayout。TabWidget就是每个tab的标签,FrameLayout则是tab内容。

1、如果我们使用extends TabAcitivty,如同ListActivity,TabHost必须设置为@android:id/tabhost
2、TabWidget必须设置android:id为@android:id/tabs 
3、FrameLayout需要设置android:id为@android:id/tabcontent 
4、参考这儿:aspx">http://blog.csdn.net/flowingflying/archive/2011/04/06/6304289.aspx

先自定义一个xml文件: 
Java代码  
<?xml version="1.0" encoding="utf-8"?>  
<TabHost xmlns:andro/>  
        </RadioGroup>  
    </LinearLayout>  
</TabHost> 

为了让tabHost显示在下方,要将RadioGroup的layout_gravity设置为bottom,再将FrameLayout的layout_weight设置为1,这样就可以将RadioGroup撑到最下方。里面定义了样式文件。

接下来就是在activity中初始化并添加tabhost: 
Java代码  
tabHost = (TabHost) findViewById(android.R.id.tabhost);  
        tabHost.addTab(Constant.tabHost.newTabSpec("Main")  
                .setIndicator(getString(R.string.main_name),null)  
                .setContent(new Intent(this, Main.class)));  
        tabHost.addTab(Constant.tabHost.newTabSpec("RunManager")  
                .setIndicator(getString(R.string.run_manager_name),null)  
                .setContent(new Intent(this, RunManager.class)));  
        tabHost.addTab(Constant.tabHost.newTabSpec("UninstallManager")  
                .setIndicator(getString(R.string.uninstall_manager_name),null)  
                .setContent(new Intent(this, UninstallManager.class))); 


初始化每个RadioButton并为其添加setOnCheck

相关文章:

  • 2021-08-28
  • 2021-06-28
  • 2021-06-23
  • 2021-06-04
  • 2022-12-23
  • 2021-08-25
  • 2021-10-24
猜你喜欢
  • 2022-12-23
  • 2021-11-02
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
相关资源
相似解决方案