SoulRayder
SoulRayder

Reputation: 5166

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

I want to create a circular button in android. This 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 a button in the layout, I will have to set the above xml as the

android:background

attribute. But then how can I put an image within the circular button I have generated. How to accomplish this within the xml itself?

Upvotes: 5

Views: 5993

Answers (3)

Shadik Khan
Shadik Khan

Reputation: 1215

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>

Upvotes: 5

Quark
Quark

Reputation: 412

Use an ImageButton and set your image with the src tag: android:src="@drawable/your_image"

Upvotes: 0

natario
natario

Reputation: 25194

If I got it you can use an ImageButton, which lets you choose both a background with android:background and a drawable resource with android:src.

Upvotes: 2

Related Questions