私はアプリをやっていて、これでタブを使いたいです。
これは、タブを管理するアクティビティです。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Resources res = getResources();
tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, WUL4Bus.class);
spec = tabHost.newTabSpec("mapa");
spec.setIndicator("Mapa",res.getDrawable(R.drawable.ic_tab_mapa));
spec.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Esquematico.class);
spec = tabHost.newTabSpec("esquemático");
spec.setIndicator("Esquemático",res.getDrawable(R.drawable.ic_tab_listado));
spec.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, ListaTickets.class);
spec = tabHost.newTabSpec("tickets");
spec.setIndicator("Tickets",res.getDrawable(R.drawable.ic_tab_bono));
spec.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, ListaFavoritos.class);
spec = tabHost.newTabSpec("favoritos");
spec.setIndicator("Favoritos",res.getDrawable(R.drawable.ic_tab_directo));
spec.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, About.class);
spec = tabHost.newTabSpec("acerca de");
spec.setIndicator("Acerca de",res.getDrawable(R.drawable.ic_tab_info));
spec.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
instancia = this;
}
これはレイアウトです:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</HorizontalScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
私の最初の問題は、アプリを実行すると正しく動作するのに、アイコンが表示されないことです。HorizontalScrollView がなくても問題はありませんでしたが、現在はアイコンが表示されていません。
もう 1 つの問題は、複数のタブではなく、1 つの画面 (Google Play と同様) に 1 つのタブのみをアプリに表示することです。
どうもありがとう