Reputation: 5166
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
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
Reputation: 412
Use an ImageButton and set your image with the src tag: android:src="@drawable/your_image"
Upvotes: 0
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