Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set button background drawable image with ripple effect in android

My Xml code:

<Button
    android:id="@+id/link_btn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/google_btn" />

I am applying Default ripple effect

<Button
    android:id="@+id/link_btn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/selectableItemBackground" />

but I need button background "@drawable/google_btn" with
"?android:attr/selectableItemBackground". it's means i need ripple effect with custom background.

like image 671
Prithiv Dharmaraj Avatar asked Sep 28 '16 04:09

Prithiv Dharmaraj


People also ask

What is ripple drawable in Android?

What is Ripple effect in Android? Ripple effect provides an instantaneous visual confirmation at the point of contact when users interact with UI elements. These UI elements could be any of the View elements. Like – Layouts, Buttons, TextViews, ListViews, etc.

What is button ripple?

Ripple touch effect was introduced with material design in Android 5.0 (API level 21). Touch feedback in material design provides an instantaneous visual confirmation at the point of contact when users interact fwith UI elements.


1 Answers

In your drawable-v21 folder you can write code for ripple effect by your own. Make a drawable xml file and set starting tag by ripple. Like this :

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorAccentDark">
    <item>
        <selector xmlns:android="http://schemas.android.com/apk/res/android" >
            <item
                android:drawable="@color/button_accent_dark"
                android:state_checked="false"/>
            <item
                android:drawable="@color/button_accent"
                android:state_checked="true" />
            <item
                android:drawable="@color/button_accent_dark" />

        </selector>
    </item>
</ripple>
like image 158
Zahidul Islam Avatar answered Oct 10 '22 07:10

Zahidul Islam