Search code examples
androidimagebuttonandroid-imagebutton

Add image in imageButton


I trying to make a circular image button like WhatsApp.

Enter image description here

I tried the below code, but I am only able to create a circular imageButton. The image did not show in the imageButton.

 <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="70dp"
        android:paddingBottom="140dp"
        android:src = "@drawable/camera"
        android:scaleType="fitXY"
        android:layout_height="70dp"
        android:background="@drawable/round"
        android:layout_gravity="center_horizontal" />

round.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <corners android:radius="100dp" />

    <stroke
        android:width="5dp"
        android:color="#090" />

</shape>

Enter image description here


Solution

  • You added android:paddingBottom=140dp. Issue with that. Check this

    <ImageButton
            android:id="@+id/imageButton"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/round"
            android:tint="@android:color/black"
            android:scaleType="fitXY"
            android:padding="5dp"
            android:src="@drawable/camera" />