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?
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>
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With