Android basics 6 -- set the rounded corner button

Source: Internet
Author: User

The button of the rounded corner is very aesthetic to implement a flat UI, but it is not too difficult to implement it. 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 = "" 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 uses shape in android: background = "@ drawable/shape. xml resource <? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: 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: layou T_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 ();}});}}:

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: 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.