سؤال

I was creating selector for ImageView, it is OK. But when i set background image to ImageView, the selector doesn't work anymore.

My ImageView (no Background Image) is

<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" />

And selector 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>

And style

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

So, is it related "android:background" and "style" attribute in ImageView ? I lost it here...

هل كانت مفيدة؟

المحلول

in order for you to make the selector work , set the selector as the background and not the style. in which case you could have something like this:

<?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"/>

the above line would display the image that you want and the selector work when you press it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top