画面の下部にタブを配置し、各タブに異なるアクティビティを表示しようとしています。
ただし、私が読んだところによると、これは電話 3.0 以降でのみ使用できます。
私が知っているほとんどの電話が 2.3 前後である場合、これは少しばかげているように思えます。
誰にもアイデアはありますか?
画面の下部にタブを配置し、各タブに異なるアクティビティを表示しようとしています。
ただし、私が読んだところによると、これは電話 3.0 以降でのみ使用できます。
私が知っているほとんどの電話が 2.3 前後である場合、これは少しばかげているように思えます。
誰にもアイデアはありますか?
これは、Android の通常のタブを使用して実装できます。xml にコードを追加するだけで済みます。
<TabHost
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:background="@android:color/background_dark"
>
<RelativeLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="@android:id/tabs">
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
style="@style/customtab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
</TabWidget>
</RelativeLayout>
</TabHost>
スタイルはこちら @style/customtab
<style name="customtab" parent="@android:style/Widget.TabWidget">
<item name="android:tabStripEnabled">false</item>
<item name="android:tabStripLeft">@null</item>
<item name="android:tabStripRight">@null</item>
</style>
下部のタブ バーには、以下の XML コードを使用します。
<?xml version="1.0" encoding="utf-8"?>
<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" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="3dp" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@android:id/tabs"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</TabHost>
以下の Java コードを使用します。
public class MainActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_screen);
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Home", getResources().getDrawable(R.drawable.home)).setContent(new Intent(this, HomeActivity.class)));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Second", getResources().getDrawable(R.drawable.invoice)).setContent(new Intent(this, SecondActivity.class)));
tabHost.setCurrentTab(0);
}
}
これを実現するには、フラグメントと下部の一連のボタンを使用するのが最適です。
したがって、ボタンがクリックされると、ユーザーがクリックした内容に対して、メイン コンテンツ領域でフラグメント トランジションを実行します。
そうは言っても、下部のタブは Android では不適切な形式です。