Android Development Study Notes: button with rounded corners

Source: Internet
Author: User

Create the XML file shape. XML in drawable-mdpi under the res directory, as shown in:

Shape. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Shape xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Shape = "rectangle"> <! -- Fill color --> <solid Android: color = "# ffffff"/> <! -- Set the four corners of the button to an arc --> <! -- Android: radius arc radius --> <corners Android: radius = "5dip"/> <! -- Padding: The interval between the text in the button and the button boundary --> <padding Android: Left = "10dp" Android: Top = "10dp" Android: Right = "10dp" Android: bottom = "10dp"/> </shape>

 

Main. xml

On Android: Background = "@ drawable/shape", the shape. xml resource is used.

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Orientation = "vertical" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <textview Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "@ string/Hello"/> <button Android: Id = "@ + ID/roundbutton" Android: TEXT = "rounded corner button" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: Background = "@ drawable/shape"/> </linearlayout>
Strings. xml
<?xml version="1.0" encoding="utf-8"?> <resources>     <string name="hello">Hello World, RoundButtonDemoActivity!</string>     <string name="app_name">RoundButtonDemo</string> </resources> 
Roundbuttondemoactivity. Java
Package COM. android. roundbuttondemo. activity; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. toast; public class roundbuttondemoactivity extends activity {button roundbutton; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); roundbutton = (button) findviewbyid (R. id. roundbutton); // use the Anonymous class to register the button event roundbutton. setonclicklistener (New onclicklistener () {public void onclick (view v) {toast. maketext (roundbuttondemoactivity. this, "you have clicked the rounded corner button", toast. length_long ). show ();}});}}
:

Transfer http://liangruijun.blog.51cto.com/3061169/630051

Related Article

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.