0

How to add custom icon on rounded button?

This is button:

 <Button
  android:layout_width="100dp"
  android:layout_height="100dp"
  android:background="@drawable/selector_button"
  android:drawableTop="@android:drawable/ic_dialog_info"
  android:paddingTop="20dp"
  android:text="Contact"
  android:textColor="#fff" />

selector_button.xml

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/selector_button_pressed" android:state_enabled="true" android:state_pressed="true" />
<item android:drawable="@drawable/selector_button_pressed" android:state_activated="true" android:state_enabled="true" />
<item android:drawable="@drawable/selector_button_pressed" android:state_enabled="true" android:state_selected="true" />
<item android:drawable="@drawable/circle" /> </selector>

and this is shape for button:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="1000dp" />
    <solid android:color="#41ba7a" />
    <stroke
        android:width="2dip"
        android:color="#03ae3c" />
    <padding
        android:bottom="4dp"
        android:left="4dp"
        android:right="4dp"
        android:top="4dp" />
</shape>

In attribute

android:drawableTop

i can't find my custom image even it is visible in drawable folder.

Josef
  • 2,648
  • 5
  • 37
  • 73

1 Answers1

0

Also, @android:drawable/ic_dialog_info is not a custom image, but rather an API platform image.

Could be because you prepend with "@android/drawable" and not just "@drawable"?

Paamand
  • 626
  • 1
  • 6
  • 17
  • sorry, i didn't see a typo. I know that ic_dialog_info is API platform image but i'm wondering why I don't see my custom image that is stored inside drawable folder? – Josef Mar 12 '18 at 20:49
  • 1
    Could be because you prepend with "@android/drawable" and not just "@drawable"? – Paamand Mar 12 '18 at 21:28
  • Good to hear. I edited the answer to reflect the actual solution. Please mark as correct ;) – Paamand Mar 14 '18 at 07:32