The Man
The Man

Reputation: 427

how to set image as background button

I am new in Android development.I created a simple project with a simple button.I'd like to set image as background (see image). I've used android:src="@drawable/id_image" and android:background="@drawable/id_image2" but the image does not appear on the entire surface of button.Any help would be appreciated enter image description here

Upvotes: 0

Views: 140

Answers (4)

Siddhesh Dighe
Siddhesh Dighe

Reputation: 2954

You can try something like this

<RelativeLayout
    android:layout_width="250dp"
    android:layout_height="400dp"
    android:background="your_background_goes_here"
    android:foreground="?android:attr/selectableItemBackground"
    android:clickable="true"
    android:centerInParent="true">

    <ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="your_icon_above_background"/>

   <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="text_for_your_image"/>

    </RelativeLayout>

Upvotes: 0

Hugo Landim
Hugo Landim

Reputation: 179

Android, you can use android.widget.ImageButton to display a normal “Button“, with a customized background image.

<ImageButton
        android:id="@+id/top_bar_btn_right_img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:src="@drawable/ic_filter" />

Upvotes: 1

Hugo_Ludo_38
Hugo_Ludo_38

Reputation: 89

when you add your button , you just go to the menu of properties and choose background / drawable and choose your image

Upvotes: 0

R. Zag&#243;rski
R. Zag&#243;rski

Reputation: 20258

You might use android:src and android:background for adding two images.

Upvotes: 0

Related Questions