1

I want to put png image over button i tried android:background but the png takes all the button what i want exactly is to use the logo png over button like this

enter image description here

the info logo is my png and "about" comes from the button text

greg-449
  • 109,219
  • 232
  • 102
  • 145

6 Answers6

5

u can use this:

android:drawableTop="@drawable/SomeIcon"

so then you get this:

<Button
android:id="@+id/damage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="about"
android:drawableTop="@android:drawable/ic_menu_info_details"/>

enter image description here

it works for me :)

Rikkert09
  • 190
  • 1
  • 1
  • 11
1

You can use a FrameLayout. In a FrameLayout, the z-index is defined by the order in which the items are added, for example

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_text" />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/my_drawable"
        android:scaleType="fitCenter"/>
</FrameLayout>

In this instance, the ImageView would be drawn on top of the Button, along the bottom center of the Button.

RPB
  • 16,006
  • 16
  • 55
  • 79
1

You can check this thread Basically, you can use:

<ImageButton
    android:id="@+id/ImageButton01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/album_icon"
    android:background="@drawable/round_button" />

As the thread says.

Community
  • 1
  • 1
Benjamin RD
  • 11,516
  • 14
  • 87
  • 157
1

Take a RelativeLayout, place ImageView inside it. Now set onClickListener on RelativeLayout. By this way you can create more complex buttons.

<RelativeLayout android:id="@+id/your_btn_id" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true" />
</RelativeLayout>
schnill
  • 905
  • 1
  • 5
  • 12
0

you can use

android:drawableTop 

to put drawable at top of Button and use appropriate padding to make it position well.

Kirtan
  • 1,782
  • 1
  • 13
  • 35
0
 <Buttton
        android:layout_width="99dp"
        android:layout_height="99dp"
        android:background = "@drawable/bg" />

bg is your custom image.

Shivputra N
  • 688
  • 7
  • 17