0

To include ripple effect for my ImageButton I created drawable-v21 folder in res and added the following code

ans_go_btn.xml :-

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="#c20586">
        <item>
            <shape android:shape="oval">
                <solid android:color="#fa09ad"/>
            </shape>
        </item>
    </ripple>
</selector>

and in drawable directory I have the below code.

ans_go_btn.xml :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape android:shape="oval"  >
            <solid android:color="@color/black"></solid>
        </shape>
    </item>
    <item android:state_focused="true">
        <shape android:shape="oval"  >
            <solid android:color="@color/light_blue"></solid>
        </shape>
    </item>
    <item >
        <shape android:shape="oval"  >
            <solid android:color="@color/blue_app"></solid>
        </shape>
    </item>
</selector>

Image button has android:background="@drawable/ans_go_btn" attribute.

In kitkat device the ImageButton appears but, not in my Lollipop device. I might be doing some clear mistakes, but I'm not being able to find it out. Please help!

Thanks

Shree Harsha S
  • 665
  • 7
  • 14

1 Answers1

0

First of all, the ans_go_btn in drawable-v21 should be:

<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <ripple
            android:color="#c20586">
            <item>
                <shape android:shape="oval">
                    <solid android:color="#fa09ad"/>
                </shape>
            </item>
        </ripple>
    </item>
</selector>

Selector should have item, other than ripple.

Then, you can change the attribute of the item.

xxxzhi
  • 471
  • 3
  • 12
  • Oh, ya. You are right. I added it and checked. Now I get image as well as the ripple. But can you please tell me how to inherit the common state related colours from drawable directory ? Thanks :) – Shree Harsha S Oct 17 '15 at 09:52
  • inherit the common state? do you mean adding item such as ``````, just add the state attribute in the item which is the childof selector. – xxxzhi Oct 17 '15 at 10:34
  • Yes exactly. I already have them in the drawable folder with the same file name as shown. My doubt is, do I need to write them again in 'drawable-v21' or is there any other way? – Shree Harsha S Oct 17 '15 at 10:41
  • oh, you should write them again in 'drawable-v21', there are no inheritance between 'drawable' and 'drawable-v21'. It is design for different version. – xxxzhi Oct 17 '15 at 10:47