How to change button shape using xml or using java?

I want to create a custom button with a form, how to do it?

+5
source share
2 answers

This is a sample button that has an oval shape. gradient indicates the starting color of the end and the angle. corners for an oval shape. Try it. Mention the name of this xml in the background of the android:background="@drawable/sample" button android:background="@drawable/sample" . Save xml to drawable .

 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#302226" android:endColor="#6D7B8D" android:angle="45"/> <padding android:left="6dp" android:top="6dp" android:right="6dp" android:bottom="6dp" /> <corners android:radius="30dp" /> </shape> 

Also check this link for custom button.

+16
source

Another way to find a button in different forms

Use image button in xml as

  <ImageButton android:id="@+id/imageButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/shape_oval" /> 

Shape_oval is an image that we can take from Google surfing or draw ourselves in paint or photoshop.

0
source

All Articles