【问题标题】:ImageView src with drawable selector ignores enabled state带有可绘制选择器的 ImageView src 忽略启用状态
【发布时间】:2012-05-03 10:36:57
【问题描述】:

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

即这不能正常工作:

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

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

【问题讨论】:

  • 您的解决方法是什么?接受的解决方案对我不起作用
  • @ThanosFisherman 在下面看到我的答案,以“可能的解决方法”开头

标签: android xml android-imageview


【解决方案1】:

尝试添加属性android:clickable="true"

【讨论】:

    【解决方案2】:

    可能的解决方法:将TextView 与复合可绘制对象一起使用:

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

    这似乎可行,并从 state_drawable 中拉出正确的可绘制对象,但不是很直观。

    【讨论】:

    • 这是唯一对我有用的解决方案。谢谢!
    【解决方案3】:

    我刚刚添加了以下属性:

    android:background="@drawable/image_selector"
    

    并且“android:src”不是必须添加的。

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

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

    希望对你有帮助...

    【讨论】:

      【解决方案4】:

      对我来说只有这个:

      image.setClickable(false); 
      

      对于 ImegeView android:enabled="false" 由于某种原因不起作用。

      【讨论】:

        猜你喜欢
        • 2012-01-07
        • 2014-02-17
        • 1970-01-01
        • 1970-01-01
        • 2014-02-14
        • 1970-01-01
        • 2023-03-23
        • 2014-05-15
        • 2011-12-05
        相关资源
        最近更新 更多