eljainc
eljainc

Reputation: 117

Setting a background image on a Button in Android

I am having a problem trying to set the background of a button to be a bitmap image. I have the following in my layout xml file:

<Button
    android:id="@+id/p1b1"
    android:layout_width="90px"
    android:layout_height="60px"
    android:layout_alignParentLeft="true"
    android:background="@drawable/gridt"


    android:text="" />

This is just the part for the button. I have the gridt.png image in my drawable-hdpi, drawable-ldpi and drawable-mdpi folders.

The button image simply shows a white box on the empty button and the corners are not rounded.

I need to do this on several buttons, but learning how to efficiently do this on one button will be a good starting point. I would like to use a Button and not an ImageButton as I have text o the button as well.

Thanks.

Upvotes: 0

Views: 5669

Answers (1)

dymmeh
dymmeh

Reputation: 22306

Use

android:drawableTop="@drawable/gridt"

This will put the text below your drawable on the button

Alternatively you can use

android:drawableBottom="@drawable/gridt"
android:drawableLeft="@drawable/gridt"
android:drawableRight="@drawable/gridt"

depending on where you want the text placed relative to the picture

Upvotes: 4

Related Questions