I know the solution on how to change it programically however I would like to set the text in XML. How do you do that? I have looked here: http://developer.android.com/reference/android/widget/TabHost.html but found no solution.
TabHost - how to change tab text in XML
Asked Answered
Did it really work? I'm getting the same problem as the others. Did you have to do extra java code for it? –
Gourley
How about ....
<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>
This way it'll look as follows:
Check out the complete tab sample here.
Hope this helps .... Cheers!
@Supuhstar: can you explain why or what error you got? –
Lahdidah
no error, just... absolutely none of this worked. The
TextView
s appear to the left of the tabs in the preview, and no tabs appear when run on an actual device. No functionality is gained and the fragments appear atop eachother –
Sumac Depends on how you use the XML above; try the following: add ids to all tabs (i.e.
TextViews
, e.g. android:id="@+id/tab1"
, ..., android:id="@+id/content1"
, ... ) and remove android:text
tags from the TabWidget
as well as undefined symbols. This results in a clean UI preview ... –
Lahdidah Thanks for the tips! I ended up changing them programmaticly –
Sumac
I'm attempting to the same thing and getting the same result as Supuhstar. Adding textviews within tabwidget just results in text to the left of the existing tabs, well seemingly created 6 tabs as opposed to the default 3. So I see your most recent comment, but if you remove android:text tags from the text views within tabwidget, youre back to tabs with no labels yes? –
Tail
You can always go into the @+id/tab1 and change it to whatever you want the tab to be called. So if you wanted it to be called "About" just change it to @+id/About in the linear layout for the specific tab.
The question is about XML. Is the formula you give an xpath query ? If so, please give an example, everybody might not read fluently xpath. –
North
Quite late on this one, but jorgensen was talking about tab IDs, by default, TabHost use ID's as tab labels. But as @gattsbr pointed out, that solution is only usable if you don't use string translation files –
Roundtheclock
© 2022 - 2024 — McMap. All rights reserved.