3

I am trying to get a button with an image working on Android. I tried the following:

<Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:icon="@mipmap/ic_launcher" />

The button shows without the image.

hasdrubal
  • 1,024
  • 14
  • 30

2 Answers2

3

#. If you want a Button with only background Image, Try this:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@mipmap/ic_launcher"/>

enter image description here

OR, you can use ImageButton as below:

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@mipmap/ic_launcher" />

enter image description here

#. If you want a Button with Text and background Image, Try this:

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BUTTON"
    android:background="@mipmap/ic_launcher"/>

enter image description here

#. If you want a Button with Text and left drawable Icon, Try this:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BUTTON"
    android:drawableLeft="@mipmap/ic_launcher"/>

enter image description here

Ferdous Ahamed
  • 21,438
  • 5
  • 52
  • 61
1

Try

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@mipmap/ic_launcher" />`
Akshay
  • 1,161
  • 1
  • 12
  • 33