android - TabHost - 如何更改 XML 中的选项卡文本

标签 android android-tabhost

我知道如何以编程方式更改它的解决方案,但我想在 XML 中设置文本。你是怎样做的?我看过这里:http://developer.android.com/reference/android/widget/TabHost.html但没有找到解决方案。

最佳答案

怎么样....

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

这样它看起来如下:

TabHost

查看完整的标签样本 here .

希望这有助于....干杯!

关于android - TabHost - 如何更改 XML 中的选项卡文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17087940/

相关文章:

Android studio 添加 Java 8 config 报错 "Could not get unknown property"

android - TabHost 和 PhoneGap

android - 如何在不超过 Android 中的 VM 限制的情况下在 tabhost 中允许多个位图画廊?

java - Android tabhost 问题...包含代码

android - 比较android中的2个ImageView

android - 使用 Google Fit api 时 Google Oauth 2.0 RESULT_CANCELED

java - 如何将额外内容传递给 TabActivity 内的 Intent ?

android - 用 FragmentActivity 和 Fragments 替换 TabActivity

java - AsyncTask 中的 android.os.NetworkOnMainThreadException

android - list 必须有标签