无法更改按钮的背景图片

时间:2018-10-29 20:44:48

标签: android android-studio android-layout

我在photoshop中创建了一个按钮图像,但是当我在应用程序中使用它时,它崩溃了,我想我需要指定尺寸的应用程序才能正常运行,而没有背景图像的按钮

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Test" />

</RelativeLayout>

button background

1 个答案:

答案 0 :(得分:1)

您是否尝试过使用ImageButton而不是Button

https://developer.android.com/reference/android/widget/ImageButton

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="sourceDrawableHere"/>