Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 267
SoulRayder Avatar asked Mar 29 '15 13:03

SoulRayder


2 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>
like image 140
Shadik Khan Avatar answered Nov 03 '22 00:11

Shadik Khan


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.

like image 31
natario Avatar answered Nov 03 '22 01:11

natario