现在在我的应用程序中,我有一个TabActivity
,其中有三个固定标签,每个固定标签包含标准Activity
。带有固定标签的操作栏
这里是相对的代码片段:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_activity);
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, Tab1Activity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("tab1").setIndicator("Tab 1", res.getDrawable(R.drawable.Tab1Icon)).setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, Tab2Activity.class);
spec = tabHost.newTabSpec("tab2").setIndicator("Tab 2", res.getDrawable(R.drawable.Tab2Icon)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Tab3Activity.class);
spec = tabHost.newTabSpec("tab3").setIndicator("Tab 3", res.getDrawable(R.drawable.Tab3Icon)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
这样每一次我选择一个选项卡上的应用程序会在屏幕上显示相关于该标签的Activity
。
我想使用ActionBar
设计模式来获得相同的结果。
现在我在具有固定标签布局只是有兴趣,你可以看到here:
我应该如何改变我的代码?
这些所谓的问题没有太大帮助:
- ActionBar Tabs - Fixed and Scrollable?
- ActionBar Tabs with multiple fragments
- Customizing ActionBar Tabs on Android 4
您是否使用API 14作为最低要求? – 2012-08-07 11:44:15
@Se_bastiaan - 在我目前的版本中没有,但是我想写一个支持API 14的新版本。 – Matteo 2012-08-07 11:52:57