2

我正在尝试获取一个带有可在 Android 上运行的图像的按钮。我尝试了以下方法:

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

该按钮显示没有图像。

4

2 回答 2

2

#. 如果你想要一个Button只有背景的Image,试试这个:

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

在此处输入图像描述

或者,您可以使用ImageButton如下:

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

在此处输入图像描述

#. 如果你想要一个ButtonwithText和 background Image,试试这个:

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

在此处输入图像描述

#. 如果你想要一个ButtonwithText和 left drawable Icon,试试这个:

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

在此处输入图像描述

于 2017-05-05T11:02:09.447 回答
1

尝试

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@mipmap/ic_launcher" />`
于 2017-05-05T10:16:45.097 回答