0

私はアンドロイドが初めてで、タブホストで簡単なアプリケーションを開発しようとしています。そして、タブホストがすべてのアクティビティに含まれるようにします。5 つのタブと 6 ~ 7 のアクティビティがあり、それらすべてをこれらの 5 つのタブに表示したいと考えています。

ここでタブアクティビティを作成します:

<?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" >


    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@android:id/tabs" />

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"

         />
</RelativeLayout>

</TabHost>

そしてここにタブを追加します:

    TabSpec tabSpec = mTabHost.newTabSpec("tab_test1");
    tabSpec.setIndicator("Map",res.getDrawable(R.drawable.world));
    Context ctx = this.getApplicationContext();
    Intent i = new Intent(ctx, DealFinderActivity.class);
    tabSpec.setContent(i); 
    mTabHost.addTab(tabSpec); 

    mTabHost.getTabWidget().setBackgroundColor(Color.GRAY);

    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator
            ("List Deals",res.getDrawable(R.drawable.database))
            .setContent(new Intent(this,ListDeals.class)));

    //      TextView textView = (TextView) findViewById(R.id.textview3);
    //      textView.setText("hello");
    mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Favorites",
            res.getDrawable(R.drawable.heart)).setContent(
                    new Intent(this, ListDeals.class)));

    mTabHost.addTab(mTabHost.newTabSpec("tab_test4").setIndicator("Settings",
            res.getDrawable(R.drawable.preferences)).setContent(
                    new Intent(this, DealDescription.class)));

    mTabHost.addTab(mTabHost.newTabSpec("tab_test5").setIndicator("About",
            res.getDrawable(R.drawable.newspaper)).setContent(
                    new Intent(this, DealDescription.class)));

ListDeals.class では、これを使用して新しいアクティビティに変更します。

        Intent myIntent = new Intent(getApplicationContext(), 
                DealMyAss.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        getApplication().startActivity(myIntent);

しかし、ここでタブビューが消えますか??

タブビューを維持する方法はありますか??

前もって感謝します

4

1 に答える 1

0

ActivityGroupはあなたが探しているものです。

名前が示すように、タブ内に複数のアクティビティが埋め込まれています。例を見てください。1つはここにあります。

タブごとに1つのActivityGroupを作成します。

于 2011-12-20T10:40:06.557 に答える