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