【发布时间】:2013-06-13 13:11:19
【问题描述】:
我知道如何以编程方式更改它的解决方案,但是我想在 XML 中设置文本。你是怎样做的?我看过这里:http://developer.android.com/reference/android/widget/TabHost.html,但没有找到解决方案。
【问题讨论】:
-
真的有用吗?我遇到了和其他人一样的问题。您是否需要为它编写额外的 java 代码?
我知道如何以编程方式更改它的解决方案,但是我想在 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>
这样它会如下所示:
查看完整的标签示例here。
希望这会有所帮助....干杯!
【讨论】:
TextViews 出现在预览中选项卡的左侧,在实际设备上运行时不显示任何选项卡。没有获得任何功能,并且片段彼此重叠
TextViews,例如android:id="@+id/tab1",...,android:id="@+id/content1",...)并从android:text 中删除android:text 标签以及未定义的符号。这会产生一个干净的 UI 预览......
您始终可以进入@+id/tab1 并将其更改为您希望调用选项卡的任何内容。因此,如果您希望将其称为“关于”,只需在特定选项卡的线性布局中将其更改为 @+id/About。
【讨论】: