从其他活动调用选项卡主机

发布于 2024-11-28 12:52:38 字数 96 浏览 0 评论 0原文

我是安卓新手。你能告诉我如何从 TabActivity 之外的其他活动中调用 TabActivity 吗?这实际上是一个菜单。我想在选择菜单选项之一后拥有 TabHost。 谢谢

I m new to android. Can you tell how can i call TabActivity from my other activity outside of TabActivity. Which is actually a menu. I want to have TabHost after selecting one of the menu option.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悸初 2024-12-05 12:52:38

如果我理解正确,您只需将 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);

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

If i understand you right,you just need to add tabhost to your new activity.Something like this :

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

and the 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);

Something like this.Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文