views:

24

answers:

1

Okay so with my code below for adding custom look to my tabs (works great), yet I am getting a border (padding or some sort of crop I assume) around my drawable image. How and where do I remedy this?

Activity:

 TabHost mTabHost = getTabHost();
 Drawable mySelector = getResources().getDrawable(R.drawable.tabselector);
 mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1" , mySelector).setContent(R.id.textview1));

partial tabselecter XML:

<selector
    android:id="@+id/myselector"
    xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    <!-- Non focused states -->
    <item
        android:state_focused="false"
        android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/darklogo"/>
    <item
        android:state_focused="false"
        android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/lightlogo" />

Main XML:

<TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:padding="0px"
            android:layout_marginBottom ="-4px"
            android:clipToPadding="false" />

Wouldnt let me post a screenshot...

A: 

It is actually quite easy if I got you right.

You just have to set the variablePadding attribute to true in your selector element.

Here is how it should look like.

<selector
android:id="@+id/myselector"
android:variablePadding="true"
xmlns:android="http://schemas.android.com/apk/res/android"&gt;
<!-- Non focused states -->
<item
    android:state_focused="false"
    android:state_selected="false"
    android:state_pressed="false"
    android:drawable="@drawable/darklogo"/>
<item
    android:state_focused="false"
    android:state_selected="true"
    android:state_pressed="false"
    android:drawable="@drawable/lightlogo" />

Note line three.

Octavian Damiean
This did not work. The problem is when I add a drawable to the tabWidget as above "item" there is a small padding around the drawable. So default, light gray tab on selected. When I add a drawable, I see my black drawable, but I also see a small 5px of the light gray around my drawable. This remains there even when I increase the size of the drawable... I need the drawable to fill the entire tab so that you dont see the default gray when selected.
JoshuaBen
Could you please try to provide some screenshots since I seriously don't really get it.
Octavian Damiean