Android Buttons With Shape Background Or Image
I want to create a button in an Android application which will be round with a color of my choosing and a plus sign as its text. Is it better (in terms of space, efficiency etc.)
Solution 1:
To do that you can create a circle shape with the help of shape drawable, but the better way to do this is to use the FloatingActionButton which is circular in shape and you can provide the icon of your choice.
Solution 2:
-First of You create drawable xml
-ic_round_shape_background
<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"><solidandroid:color="#000" /><!--color code which you are use instead #000--><cornersandroid:bottomRightRadius="8dp"android:bottomLeftRadius="8dp"android:topRightRadius="8dp"android:topLeftRadius="8dp"/></shape>
//Create xml and use background like below
activity_main.xml
<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/ic_round_shape_background"
/>Solution 3:
please try the below code.
create a background.xml in drawable folder and paste this code.
`
<solidandroid:color="@color/colorPrimary"></solid><strokeandroid:width="2dp"android:color="@color/colorPrimary"></stroke><paddingandroid:left="5dp"android:right="5dp"android:top="5dp"></padding><cornersandroid:radius="5dp"></corners>`
in Layout
<LinearLayout
android:id="@+id/place_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:gravity="center"
android:orientation="horizontal">
` <ImageViewandroid:layout_gravity="center_vertical"android:layout_width="20dp"android:layout_height="20dp"android:background="@drawable/image" /></LinearLayout>`
Post a Comment for "Android Buttons With Shape Background Or Image"