简体   繁体   中英

How to add image buttons with ripple effect in cardview?

I'm looking at implementing a cardview which has a button with the ripple effect. I'm talking about something like this : https://lh5.ggpht.com/uTRdkJMNyy3KasauJsyGTTRHn5EZBtmA3-BVHCaHWiqBIF_XQmJg_MuE8OdisvefdEk=h900-rw )

I'm trying to implement the download/share button as present on those cards. Should I be using an ImageButton or something else? Also, how can I extend the same support for pre-lollipop devices?

UPDATE:

This is the code I'm using right now. It gives me an image button but I'n not able to get touch/ripple effects. The android:foreground property works for cardView and gives the ripple effect, but not for ImageButton.

      <ImageButton
            android:id="@+id/ib_open_map"
            android:background="@drawable/ic_directions_grey600_36dp"
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

I think this can be interesting for you. You will have to import or link the library to be able to use it.

Here is the link to the library : Link to the library

It is easy to use and it is based on imageView.

Hope it helps you :) Let me know

EDIT Editing my link for your update :) Take a look at this : MaterialRipple

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM