6

I have this application that I am working on and the user can mark some items as a favorite. I want to use a heart shaped button for this functionality instead of the casual one is it possible?

Toka A. Amin
  • 156
  • 1
  • 2
  • 16
  • Yes, it's possible. Next question, please. (*Is it possible?* is not a specific question, and therefore isn't going to help you much. This site is for **specific questions**. You may want to spend some time reading [ask] for some suggestions about how to ask questions in a way that will improve your chances of getting help.) – Ken White Aug 10 '17 at 15:58
  • question already answered : https://stackoverflow.com/questions/13861416/android-custom-shape-button – HellYeah Aug 10 '17 at 16:02

2 Answers2

15

You can use VectorAssets as below in XML.

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M12,21.35l-1.45,-1.32C5.4,15.36 2,12.28 2,8.5 2,5.42 4.42,3 7.5,3c1.74,0 3.41,0.81 4.5,2.09C13.09,3.81 14.76,3 16.5,3 19.58,3 22,5.42 22,8.5c0,3.78 -3.4,6.86 -8.55,11.54L12,21.35z"/>
</vector>

You can create VectorAssets doing: new Vector Asset > Change Icon -- Here you can choose love vector asset. These VectorAssets, you can store in the drawable folder. Then you can import than in your XML layout file as

@drawable/<name_of_vectorAsset_xml>

For the demo, please see below picture. The VectorAsset XML file is ic_favorite_black_24dp enter image description here

You can change the color of the VectorAsset also. On click, you can replace VectorAsset with another Red colored VectorAsset to represent it favorite and so on.

Uddhav P. Gautam
  • 7,362
  • 3
  • 47
  • 64
  • To be clear, you can choose File -> New -> Vector Asset (it's not in any of the submenus, it's right inside the large 'New' menu) Then you can click the icon next to "Clip Art" and change to a different clip art icon You can search for "Fav" in the list of clip art to see a Heart PS: I'd recommend changing the Opacity to near 100% so you can actually see it, otherwise it's a transparent (ghost) image – davidfrancis Jul 24 '20 at 09:52
0

You can do it by adding a heart graphic asset and then putting it in an ImageButton, then for the animations you should work some more.

There is a Star/Rate button native, but nancy fancy.

I would recommend this for what you are looking for: https://android-arsenal.com/details/1/3038

cutiko
  • 9,887
  • 3
  • 45
  • 59