Pleasure
Pleasure

Reputation: 13

(Android) How to change the size of the tabs in a tabWidget ?

I need to change the size of the 2 tabs in a tabWidget but I tried this :

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

But it didnt work.

Here is what I got :

    TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);

    TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
    TabSpec secondTabSpec = tabHost.newTabSpec("tid1");


    firstTabSpec.setIndicator("Calendrier").setContent(new Intent(this,PremiereTab.class));
    secondTabSpec.setIndicator("Convoiturage").setContent(new Intent(this,DeuxiemeTab.class));

    tabHost.addTab(firstTabSpec);
    tabHost.addTab(secondTabSpec);

And my XML File :

<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:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </TabWidget>

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </FrameLayout>

</LinearLayout>   
</TabHost>

I searched for a long time without success, help pls !

Upvotes: 1

Views: 471

Answers (1)

prabhakaran
prabhakaran

Reputation: 678

you can change ur xml :

<TabWidget
    android:id="@android:id/tabs"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
</TabWidget>

To

<TabWidget
    android:id="@android:id/tabs"
    android:layout_width="fill_parent"
    android:layout_height="30dp" >
</TabWidget>

I hope this will help you..

Upvotes: 1

Related Questions