In primo luogo, definire un frametab nel layout principale.
<tabhost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent">
<linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp">
<tabwidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content">
<framelayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp">
</framelayout>
</tabwidget>
</linearlayout>
</tabhost>
Quindi, creare un'attività si estende da TabActivity
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, DashboardActivity.class);
spec = tabHost.newTabSpec("home").setIndicator("Home", res.getDrawable (R.drawable.ic_tab_dashboard)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, CreditCardActivity.class);
spec = tabHost.newTabSpec("sample1").setIndicator("Sample Tab",res.getDrawable (R.drawable.ic_tab_sample1)).setContent(intent);
tabHost.addTab(spec);
Se si vuole scheda rolover, l'uso di layout selettore:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/helpblue" android:state_selected="true">
<item android:drawable="@drawable/helpgray"></item>
</item></selector>
Ecco le immagini di esempio.
alt text http://rayyildiz.com/wp-content/uploads/2010/06/android_sample_tab-201x300.pngalt text http://rayyildiz.com/wp-content/uploads/2010/06/android_sample_tab2-201x300.png
"... ognuno con una diversa attività" - probabilmente vuol dire diverso "Visualizza". –
L'estensione di 'TabActivity' è necessaria solo per l'attività principale che ospita le schede. Tutte le altre attività nelle schede possono semplicemente estendere l'attività e verranno eseguite correttamente. – codinguser