Android Ripple effect for ImageView "state_select" not working

I am developing a Ripple effect for an ImageView in Lolipop. My available XML looks like this.

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:color="?android:colorControlHighlight"
    tools:targetApi="21">
    <item android:state_selected="true" android:drawable="@drawable/image_selected"/>
    <item android:state_pressed="true" android:drawable="@drawable/image_selected"/>
    <item android:drawable="@drawable/image_unselected"/>
</ripple>

      

And in XML, I provide SRC ImageView as shown below.

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:id="@+id/iv_image"
        android:scaleType="fitXY"
        android:src="@drawable/bg_tab_item" />

      

My problem is Activity.java, if I mention

ImageView.setSelected(true);

      

The selected image is not displayed.

Please help me where I am doing wrong.

+3


source to share





All Articles