How Android uses code to display components such as edit boxes as rounded corners

Source: Internet
Author: User

Fillet button Implementation

Rounded buttons are very common, and sometimes you may use PS to process rounded pictures to achieve the desired effect .

This effect is achieved today with a short code. (because it has nothing to do with engineering, it's just an effect, so I'm going to write a single XML file to do a simple demo)

1. Create an XML file under Layout with the name a


2. Drag a button directly from the project (left-click, drag directly to the white area) or write a button yourself in the code .

3. Create a folder withthe name drawable under res

4. Create an xml file named shape under the drawable folder

and write the code.


<?xml version= "1.0" encoding= "Utf-8"?>
<shape xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:shape= "Rectangle" >


<!--filled Colors--
<solid android:color= "#FFFFFF"/>
<!--set the four corners of the button arc--
<!--Android:radius Arc radius--
<corners android:radius= "25dip"/>


<!--the spacing between the text and the button boundary in the Padding:button
<padding
Android:bottom= "10DP"
android:left= "10DP"
android:right= "10DP"
android:top= "10DP"/>


</shape>



Shape is a class

where android:shape="Rectangle" is the shape of a rectangle

Of course there are other properties such as Oval ( Circle ).....

Color I set the background color to white

Padding equivalent to margin


6. now open the a.xml file and then add it under the button

Android:background= "Drawable/shape" This Code

Now you can run it and discover the effect.




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

How Android uses code to display components such as edit boxes as rounded corners

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.