0

我正在尝试创建一个在 Home_Tab Activity 中具有选项卡视图的 android 应用程序。它有 4 个标签。我想对视图进行一些修改,也就是说,当我单击第一个选项卡时,它会在该选项卡下显示 4 个子选项卡。如何创建它,我的代码如下

         public class Home_tab extends TabActivity {


    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_main);

    Resources ressources = getResources(); 
    TabHost tabHost = getTabHost(); 

    // Android tab
    Intent intentAndroid = new Intent().setClass(this, CoalActivity.class);
    TabSpec tabSpecAndroid = tabHost

      .newTabSpec("Android")

      .setIndicator("", ressources.getDrawable(R.drawable.tab_dis))
      .setContent(intentAndroid);




    // Apple tab
    Intent intentApple = new Intent().setClass(this, EnergyActivity.class);
    TabSpec tabSpecApple = tabHost
      .newTabSpec("Apple")
      .setIndicator("", ressources.getDrawable(R.drawable.tab_foc))
      .setContent(intentApple);

    // Windows tab
    Intent intentWindows = new Intent().setClass(this, PowerActivity.class);
    TabSpec tabSpecWindows = tabHost
      .newTabSpec("Windows")
      .setIndicator("", ressources.getDrawable(R.drawable.tab_nor))
      .setContent(intentWindows);

    // Blackberry tab
    Intent intentBerry = new Intent().setClass(this, TopNewsActivity.class);
    TabSpec tabSpecBerry = tabHost
      .newTabSpec("Berry")
      .setIndicator("", ressources.getDrawable(R.drawable.tab_sel))
      .setContent(intentBerry);

    // add all tabs 
    tabHost.addTab(tabSpecAndroid);
    tabHost.addTab(tabSpecApple);
    tabHost.addTab(tabSpecWindows);
    tabHost.addTab(tabSpecBerry);

    //set Windows tab as default (zero based)
    tabHost.setCurrentTab(0);


              }


                }
4

1 回答 1

1

您需要再次创建类 (CoalActivity) 扩展 tabactivity。并创建新的标签规范简单......

于 2013-01-30T08:31:53.140 回答