0

我正在为 ImageView 创建选择器,没关系。但是当我将背景图像设置为 ImageView 时,选择器不再起作用。

我的 ImageView(无背景图像)是

<ImageView
  android:id="@+id/dashboard"
  style="@style/glow_effect_style"
  android:layout_width="35dp"
  android:layout_height="35dp"
  android:layout_marginLeft="10dip"
  android:layout_marginRight="10dip" />

和选择器glow_effect_style.xml

<?xml version="1.0" encoding="UTF-8"?>
     <selector xmlns:android="http://schemas.android.com/apk/res/android">

     <item android:drawable="@drawable/glow_effect" android:state_pressed="true"/>

</selector>

和风格

<style name="glow_effect_style">
    <item name="android:background">@drawable/glow_effect_selector</item>
</style>

那么,它是否与 ImageView 中的“android:background”和“style”属性相关?我在这里丢了...

4

1 回答 1

0

为了使选择器起作用,请将选择器设置为背景而不是样式。在这种情况下,你可以有这样的东西:

<?xml version="1.0" encoding="UTF-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">

 <item android:drawable="@drawable/glow_effect" android:state_pressed="true"/>
 <item android:drawable="@drawable/actual_image_here"/>

<item android:drawable="@drawable/actual_image_here"/>

上面的行将显示您想要的图像,并且当您按下它时选择器会起作用。

于 2014-01-14T08:34:32.580 回答