android - 如何通过 TabBars 调用 Activity

标签 android

我正在制作一个使用标签栏的应用程序。 现在我需要知道的是,如何在我的代码中通过 setOnTabChangedListener() 打开其他 Tab

例如。我目前在选项卡中,当我点击第二个选项卡时,它应该调用第二个选项卡的 Activity 。

最佳答案

看下面的代码

 TabHost tabHost = getTabHost(); // The activity TabHost
        TabHost.TabSpec spec; // Reusable TabSpec for each tab
        Intent intent; // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the Movies tab.
        intent = new Intent().setClass(this, BarActivity.class);
        // Initialise a TabSpec for the Movies tab and add it to the TabHost.
        spec = tabHost.newTabSpec("Nights").setIndicator("Nights").setContent(intent);
        tabHost.addTab(spec);

        // Do the same things for the Theatres tab.
        intent = new Intent().setClass(this, BarActivity.class);
        spec = tabHost.newTabSpec("Weeks").setIndicator("Weeks").setContent(intent);
        tabHost.addTab(spec);

关于android - 如何通过 TabBars 调用 Activity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4966105/

相关文章:

java - Android,有没有API可以从邮箱(本地/网络)读取邮件?

java - 如何在同一个 Activity 中切换 View ?

android - 如何要求用户通过代码对我的应用进行评分?

java - Android - 如何正确挂起 OpenGL

android - 如何检查 autoCompleteTextView 中的下拉状态(显示或隐藏)?

android - 事件未显示在 firebase 上

android - 如何将图库中的图像上传到 ImageView 中?

android - 渐进式下载的建议视频设置。 (安卓)

android - float 操作按钮 layout_margin(Bottom) 对底部边距没有影响

带有子项目的 Android Gradle 构建