Custom button shape (circle, ellipse)

Source: Internet
Author: User

Here are 2 ways to change the button shape, one directly by setting a circular background image,

Another way to do this is by referencing a custom shape file. See below for details:

--------Main_menu_btnshape.xml the custom shape XML file

<?XML version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "Http://schemas.android.com/apk/res/android"Android:shape= "Oval">    <!--the color of the fill -    <SolidAndroid:color= "#FFFFFF"/>     <!--set the Four corners of the button as arcs -     <!--Android:radius radius of Arc -     <CornersAndroid:radius= "360dip"/>         <!--The spacing between the text inside the Padding:button and the Button boundary -     <paddingAndroid:left= "10DP"Android:top= "10DP"Android:right= "10DP"Android:bottom= "10DP"     /></Shape>

-----Main Layout File

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"    ><TextViewAndroid:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "@string/soft_info"/> <!-Set background directly--><ButtonAndroid:id= "@+id/roundbtn1"Android:background= "@drawable/btn_oval"Android:layout_width= "50dip"Android:layout_height= "50dip"    />     <!-Call shape custom XML file--><ButtonAndroid:id= "@+id/roundbtn"Android:text= "ellipse button"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@drawable/main_menu_btnshape"    />      </LinearLayout>

----acitivity File

 Public class extends Activity {    /***/    @Override    publicvoid  onCreate (Bundle savedinstancestate) {        super. OnCreate (savedinstancestate);        Setcontentview (R.layout.main);    }}

Custom button shape (circle, ellipse)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.