TabWidget - How to set position of indicator text?
i'm trying to use TabHost and TabWidget in my Android application. This is my layout main.xml:
<TabHost
android:id="@+id/mainTabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="65px"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/contentTags"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/contentPreferences"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
</FrameLayout>
</TabHost>
And my code:
final TabHost mainTabHost = (TabHost) this.findViewById(R.id.mainTabHost);
mainTabHost.setup();
final TabHost.TabSpec tabSpecTags = mainTabHost.newTabSpec("tabTags");
tabSpecTags.setIndicator(this.getString(R.string.tab_name_tags));
tabSpecTags.setContent(R.id.contentTags);
mainTabHost.addTab(tabSpecTags);
final TabHost.TabSpec tabSpecPreferences = mainTabHost.newTabSpec("tabPreferences");
tabSpecPreferences.setIndicator(this.getString(R.string.tab_name_preferences));
tabSpecPreferences.setContent(R.id.contentPreferences);
mainTabHost.addTab(tabSpecPreferences);
The problem is that i do not want my tabs to be so tall (65px). However, if i set the layout_height of the TabWidget to e.g. 30px, i can't see the tab labels (indicator) on the tabs at all.
Seems like there is a "minimum required" height for the TabWidget (65px?) and the indicator is positioned at the bottom of this 65px?
Is there a way to adjust the positioning of the indicator?
Thanks!
Asked by: Caroline880 | Posted: 20-01-2022
Answer 1
However, if i set the layout_height of the TabWidget to e.g. 30px, i can't see the tab labels (indicator) on the tabs at all.
Note that the techniques for doing this won't necessarily be reliable in future Android releases, if they change up how a TabHost
is constructed.
Is there a way to adjust the positioning of the indicator?
Starting with API Level 4 (a.k.a., Android 1.6), TabHost.TabSpec
accepts a View
as the indicator via setIndicator()
. I haven't tried it, but it may give you greater control over the layout of an individual tab's indicator.
Answer 2
i see... when u addTab, usually we use setIndicator like this: QTabHost.addTab(QTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").bla bla....
u can use TextView to replace "TAB 2", became like this:
tview=new TextView(this); tview.setText("Title here"); QTabHost.addTab(QTabHost.newTabSpec("tab_test2").setIndicator(tview).bla bla....
all u need is just modify the textview. Thanks... ^^
Answered by: First Name756 | Posted: 21-02-2022Answer 3
int iH = getTabWidget().getLayoutParams().height;
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = iH;
}
Answered by: Kimberly476 | Posted: 21-02-2022
Answer 4
for (int i = 0; i < 4; i++) {
tabhost.getTabWidget().getChildAt(i).getLayoutParams().height = 50;
}
by using this we can do very easily
Answered by: William675 | Posted: 21-02-2022Similar questions
android - TabWidget Height
Is it possible to set the TabWidget height and have the tab labels adjust?
If I set the TabWidget height too small, then the labels are hidden from view.
<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">
<LinearLayout
android:orientat...
android - TabWidget Activity Handling - Does it Create a New Activity EVERY Time?
When a TabWidget is using intents to designate the target Activity for each tab, is there any special handling of those Activities on the Activity Stack outside of the default operation?
For Instance, if my app has tabs A, B, and C, and I click them in this order––A, B, A, C, A, B––how will the Activity stack change?
My understanding of the default operation, if startActivity() is called each time o...
How to close TabWidget when a tab is selected in Android
In Android, how do I close TabWidget when a tab is selected?
I want close the TabWidget where some tab is selected.
TabWidget not stable at the bottom in Android? Why?
I set my tabWidget at the bottom. When i want to edit the edittext the keyboard will raise up. But the tab widget come above the keyboard. To support for the multiple screen i set the android:layout_weight="1.0". After that, I got this problem i added my layout code below. any idea to make the TabWidget at the bottom stably?
Code:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:androi...
android - Color TabWidget
Is there a way that I can color the TabWidget View? Both the idle and selected colors? That way my app can look a little more personalized, ya know.
Thanks!
android - TabWidget buttons
Is it possible to display tab buttons at bottom, rather than top? I need to port an application, which was originally designed on iPhone, where the default "tab" buttons are at the bottom.
patch - Existing patches for android tabwidget to allow tabs on left-hand side?
My employer is having me work on an android application with very specific UI requirements. Specifically, we need an interface that looks exactly like a TabWidget interface. However, having the tabs on the left hand side is an absolute must. We aren't going to be deploying this application to any android phones, its for an in house device, and as such don't have any problem violating any design considerations that the andr...
tabwidget - Android: Tabs at the BOTTOM
I've seen some chatter about this, but nothing definite.
Is there a way to put the tabs in a TabWidget to the bottom of the screen?
If so, how?
I've tried the following, but didn't work:
a) setting the tabwidget below the framelayout
b) setting the tabwidget's gravity to "bottom"
Thanks!
llappall
tabwidget - How to remove the selected tab in Android?
What should I do to remove only the selected tab in android?
Is there anything like remove tab or anything that helps me to remove a tab in the TabWidget class or in another class of the Android API?
android - Adding spinner via java code rather than XML in Tabwidget
I'm new to android. Recently I learn how to create Tabwidget. This function is useful. But I find that I cannot add the widgets I want in R.layout.xxxx. So I try to do it by java code. But unfortunately it failed.
By using XML, I do the following. The program works without problem.
public class ShowBalanceActivity extends Activity implements AdapterView.OnItemSelectedListener
{
private Spinner mon...
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android