user3730056
user3730056

Reputation: 13

android ripple effect crashes in pre-lollipop even when I added drawable-21

Ripple effect works fine but crashes below lollipop, So I added drawable-v21/animation_ripple but result is the same. What to do, Here is my code:-

XML file:

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/animation_ripple"
    android:text="Click Me"
    android:textColor="#ccc"/>

drawable/animation_ripple

<?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="#4d6670"
    tools:targetApi="lollipop">
    <item android:id="@android:id/mask">
        <shape android:shape="rectangle">
            <solid android:color="#4d6670" />
        </shape>
    </item>
    <item >
        <shape android:shape="rectangle">
            <solid android:color="#62bae0" />
        </shape>
    </item>
</ripple>

drawable-v21/animation_ripple

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:color="#4d6670"
    >
    <item android:id="@android:id/mask">
        <shape android:shape="rectangle">
            <solid android:color="#4d6670" />
        </shape>
    </item>
    <item >
        <shape android:shape="rectangle">
            <solid android:color="#62bae0" />
        </shape>
    </item>
</selector>

Upvotes: 0

Views: 735

Answers (2)

gatti
gatti

Reputation: 1133

It should be the other way around: drawable-v21 should contain <ripple ... tags and drawable the regular <selector ... tags. Everything under the drawable-v21 folder will be used from Lollipop on, not the other way around

Upvotes: 2

Muhib Pirani
Muhib Pirani

Reputation: 775

in drawable-v21 add your rippledrawable and in drawable add the selector drawable , as <ripple> </ripple> tags are used for api >=21

Upvotes: 2

Related Questions