Custom tabs are not responding to pressed state
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/tab_profile_pressed_mdpi" />
<item android:drawable="@drawable/tab_profile_unselected_mdpi" />
</selector>
And how I set them:
((ImageView)tabHost.getTabWidge开发者_JAVA百科t().getChildTabViewAt(i).findViewById(R.id.single_tab_img)).setImageResource(unselected_img[i]);
You need to use setBackgroundResource
not setImageResource
. State drawables work on the background image, not the foreground image.
I believe you need another xml file that lays out what will happen when the tab is pressed.
Example: tab.xml
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false" android:drawable="@drawable/tab_bg_selected" />
tab_bg_selected
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#A8A8A8" android:centerColor="#7F7F7F"
android:endColor="#696969" android:angle="-90" />
</shape>
精彩评论