android - ImageView 状态不变

标签 android android-imageview

我使用选择器 来更改ImageView 的可绘制对象。

即当用户按下图像时,drawable 应该改变。

在 layout.xml 中:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="73dp"
    android:src="@drawable/ic_submit_selector" />

ic_submit_selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/ic_submit_pressed" android:state_focused="true" android:state_pressed="true"/>
    <item android:drawable="@drawable/ic_submit_pressed" android:state_focused="false" android:state_pressed="true"/>
    <item android:drawable="@drawable/ic_submit" android:state_focused="true"/>
    <item android:drawable="@drawable/ic_submit_pressed" android:state_focused="false" android:state_pressed="false"/>

</selector>

但是drawable并没有改变。

最佳答案

<ImageButton
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="73dp"
    android:src="@drawable/ic_submit_selector" />

不是

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="73dp"
    android:src="@drawable/ic_submit_selector" />

关于android - ImageView 状态不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22274793/

相关文章:

android - 更改android中的通知铃声

android - 向 ImageView 添加渐变

android - 如何更改 ImageView 的图像?

java - 尝试在对话框中使 ImageView 全尺寸不起作用

android - 从不同的线程访问非托管对象抛出 IllegalStateException

android - 为什么 Fragments 需要交易?

android - 使用退出按钮关闭应用程序

android - 在将中心点保持在同一位置的同时缩放 ImageView 的图像

Android facebook sdk appinvites AppInviteDialog白屏