来自其他活动的呼叫标签主机

时间:2011-08-08 06:31:51

标签: android user-interface android-tabhost

我刚接触到android。您能告诉我如何从TabActivity之外的其他活动中调用TabActivity。这实际上是一个菜单。我想在选择其中一个菜单选项后有TabHost。 感谢

1 个答案:

答案 0 :(得分:0)

如果我理解你的话,你只需要将tabhost添加到你的新活动中。这样的事情:

Intent intent = new Intent(MainClass.this, TabActivity.class);
startActivity(intent);

和TabActivity.class:

Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, Collection.class);
        spec = tabHost.newTabSpec("collection").setIndicator("Collection",
                          res.getDrawable(R.drawable.ic_tab_collection))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Store.class);
        spec = tabHost.newTabSpec("store").setIndicator("Store",
                res.getDrawable(R.drawable.ic_tab_store))
            .setContent(intent);
        tabHost.addTab(spec);

像这样的东西。希望这有帮助

相关问题