带有可绘制选择器的ImageView src忽略启用状态

时间:2012-05-03 10:36:58

标签: android xml android-imageview

使用状态选择器作为ImageView的src时,enabled="false"被忽略。

即。这不能正常工作:

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:enabled="false"
        android:src="@drawable/state_drawable" >

P.S。 : 我有一个丑陋的解决方法,我会很快将其作为答案发布,如果您对此行为有更好的解释或解释,请告诉我。

3 个答案:

答案 0 :(得分:21)

尝试添加属性android:clickable =“true”

答案 1 :(得分:1)

可能的解决方法:使用带有复合drawable的TextView

<TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:drawableLeft="@drawable/state_drawable"
     android:enabled="false" />

这似乎有效,并从state_drawable中拉出正确的drawable,但不是很直观。

答案 2 :(得分:1)

我刚刚添加了以下属性:

android:background="@drawable/image_selector"

和&#34; android:src&#34;没有必要添加。

现在,在您的示例中,它应如下所示:

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:background="@drawable/state_drawable" >

希望它有所帮助...

相关问题