2011-10-03 23 views
0
<?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> 

我该如何设置它们:自定义选项卡不响应按下状态

((ImageView)tabHost.getTabWidget().getChildTabViewAt(i).findViewById(R.id.single_tab_img)).setImageResource(unselected_img[i]); 

回答

0

您需要使用setBackgroundResourcesetImageResource。状态drawables工作在背景图像上,而不是前景图像。

0

我相信你需要,规定了按下该标签时,会发生什么其他的XML文件。

例子: 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> 
+0

没有。这是完全错误的。 – hunterp

+0

我从我的一个应用程序复制并粘贴它。实际上它工作得很好。 – tier1

+0

证明...检查出来。 http://joshclemm.com/blog/?p=136 – tier1

相关问题