我的应用程序的第一个屏幕中有五个选项卡,我希望标签在整个应用程序中保持一致,这意味着当我移动到新活动时,这些也在该屏幕中可见。请提前给我一些建议。这是标签代码
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, Home.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("home")
.setIndicator("Home", res.getDrawable(R.drawable.select))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
// Do the same for the other tabs
intent = new Intent().setClass(this, Hypnosis.class);
spec = tabHost.newTabSpec("hypnosis")
.setIndicator("Hypnosis", res.getDrawable(R.drawable.select))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SelfDevelopment.class);
spec = tabHost
.newTabSpec("self development")
.setIndicator("Self Development",
res.getDrawable(R.drawable.select)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Read.class);
spec = tabHost.newTabSpec("read")
.setIndicator("Read", res.getDrawable(R.drawable.select))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Faq.class);
spec = tabHost.newTabSpec("faq")
.setIndicator("FAQ", res.getDrawable(R.drawable.select))
.setContent(intent);
tabHost.addTab(spec);
答案 0 :(得分:1)
我完全理解您的问题,为了使TabBar在整个应用程序中保持一致,您必须在Tab Activity中实现嵌套活动。
有关Tab Activity中嵌套活动的最佳示例,请看一下这个示例:http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/,我也在我的应用程序中实现了它,它的工作正常。