我正在制作一个使用标签栏的应用程序。
现在我需要知道的是,如何在我的代码中通过 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/