开发者_开发问答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">
<!-- 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...
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">
<!-- 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.
精彩评论