現在在我的應用程序中,我有一個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