9

プログラムで変更する方法についての解決策は知っていますが、テキストを XML で設定したいと考えています。どうやってそれをしますか?私はここを見てきました: http://developer.android.com/reference/android/widget/TabHost.htmlしかし、解決策が見つかりませんでした。

4

2 に答える 2

8

どうですか....

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TabHost 
        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">
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:tag="tab0"
                    android:text="Tab 1"
                    android:background="@android:drawable/btn_star_big_on"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    />
                <TextView
                    android:tag="tab1"
                    android:text="Tab 2"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    />
                <TextView
                    android:tag="tab2"
                    android:text="Tab 3"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    />

            </TabWidget>

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

                <TextView
                    android:text="Hallo1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" />
                <TextView
                    android:text="Hallo2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" />
                <TextView
                    android:text="Hallo3"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" />

            </FrameLayout>
        </LinearLayout>
    </TabHost>

</RelativeLayout>

このようにすると、次のようになります。

タブホスト

完全なタブのサンプルはこちらでご覧ください

これが役に立てば幸いです....乾杯!

于 2013-06-13T13:30:26.577 に答える
1

いつでも @+id/tab1 に入り、タブを呼び出したいものに変更できます。したがって、「About」という名前にしたい場合は、特定のタブの線形レイアウトで @+id/About に変更してください。

于 2014-12-28T06:55:23.273 に答える