現在、私のアプリケーションには、TabActivity
それぞれ標準を含む 3 つの固定タブがある があります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
同じ結果を得るためにデザインパターンを使用したいと思います。
今のところ、ここでわかるように、固定されたタブレイアウトに興味があります:
コードを変更するにはどうすればよいですか?
これらのSOの質問はあまり役に立ちませんでした: