I’m going to show you to implement ripple effect in your android buttons. Now, you can easily add ripple effect in your buttons, layouts, textviews, etc. and you can also change its color. Note that, this ripple effect will only show on device running lollipop and above.

  1. Create new file in layout folder name is “ripple_layout.xml”
    <pre><?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="20dp"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Add Ripple Effect"
            android:gravity="center"
            android:textSize="30sp"
            android:textColor="#78AB46"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Click me"
            android:textColor="#000000"
            android:layout_marginTop="20dp"/>
    </LinearLayout></pre>
    [/xml]</li>
    	<li>create a new file in drawable folder  name is "ripple.xml"
    
    <pre><?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="#f816a463"
        tools:targetApi="lollipop">
        <item android:id="@android:id/mask">
            <shape android:shape="rectangle">
                <solid android:color="#f816a463" />
            </shape>
        </item>
    </ripple></pre>
    

    layout-2016-04-09-170911
    result:-
    ripple_effect

Advertisements