How to create a circular button in an android with an image in the background?

I want to create a circular button in android. This is the xml I am using:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#9F2200"/>
<stroke android:width="2dp" android:color="#fff" />
</shape>

Now, when I put the button in the layout, I have to set the above xml as

android:background

attribute. But then how can I put the image in the round button that I created. How to execute this inside xml itself?

+4
source share
3 answers

You can do this using FrameLayout

<FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:background="your selector" >

            <Button
                android:id="@+id/fbLogin"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:background="yourimage"
                android:gravity="center"/>
        </FrameLayout>
+3
source

If I succeed, you can use ImageButtonone that allows you to select the background with android:backgroundand the resource with the resource android:src.

+1
source

ImageButton src: android:src="@drawable/your_image"

0

All Articles