Manoj MM
Manoj MM

Reputation: 490

Android Tab Icon are not occupying full space

Hello I am beginner to the android development. I want to create a tab structure.Where i want every tab to have icon. When i am specifying icon through xml it does reflect in tab.But icon is not occupying full space. Please help me with this. here is my tab xml

<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"
    android:background="#000000">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >

        <TabWidget
                     android:id="@android:id/tabs"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" 
                     android:layout_alignParentBottom= "true"
                     />
        <FrameLayout
                     android:id="@android:id/tabcontent"
                     android:layout_width="fill_parent"
                     android:layout_height="fill_parent"
                     android:layout_above= "@android:id/tabs"
                     android:padding="5dp" />
    </RelativeLayout>
</TabHost>

Following is my xml which i am using for tab to have icon.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/home" android:state_selected="true"/>

<item android:drawable="@drawable/homefade"/>

</selector>

and this is the java code which i am using to apply icon.

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

    tabHost.addTab(tabHost.newTabSpec(HOME_TAB).setIndicator("", getResources().getDrawable(R.drawable.tab_home_config)).setContent(
            new Intent(this, HomeActivity.class)));

Upvotes: 0

Views: 1408

Answers (1)

Manoj MM
Manoj MM

Reputation: 490

I figured it out.. Need to set padding to zero that's it.

for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++)
{
tabHost.getTabWidget().getChildAt(i).setPadding(0,0,0,0);
}

Upvotes: 4

Related Questions