Home » Android » android – TabWidget Height

android – TabWidget Height

Posted by: admin June 15, 2020 Leave a comment

Questions:

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:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp">
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="30px" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:padding="5dp" />
    </LinearLayout>
</TabHost>

Thanks

How to&Answers:

Android 1.6 added a setIndicator() method on TabSpec that accepts a View. I have not tried it yet, but my understanding is that it will give you greater control over the tabs.

Answer:

The following code adjusts the height on the tabs:

for (int i = 0; i < tabHost.getTabWidget().getTabCount(); i++) {
    tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 33;
}  

However, this will create a defect on the background color of the un-selected tab. I don’n know how to solve this yet. Some forums suggest it is not solvable without making a custom tab widget.

Answer:

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

Answer:

Tab hight is frame work dependent.you should customize it from there only or customize some other view to look like that.