Android Development Learning Note: Rounded button

Source: Internet
Author: User

Tags: Android Button casual fillet mobile development

The drawable-mdpi in the Res directory establishes the XML file Shape.xml, as shown in:

Shape.xml
  1. <? XML version= "1.0" encoding="UTF-8"?>
  2. <shape
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:shape="Rectangle">
  5. <!--filled colors--
  6. <solid android:color="#FFFFFF" />
  7. <!--set the four corners of the button arc--
  8. <!--Android:radius arc radius--
  9. <corners android:radius="5dip" />
  10. <!--the spacing between the text and the button boundary in the Padding:button
  11. <padding
  12. android:left="10DP"
  13. android:top="10DP"
  14. android:right="10DP"
  15. android:bottom="10DP"
  16. />
  17. </shape>
Main.xml

Shape.xml resources were used in android:background= "@drawable/shape"

  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. >
  7. <TextView
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. android:text="@string/hello"
  11. />
  12. <Button
  13. android:id="@+id/roundbutton"
  14. android:text="fillet button"
  15. android:layout_width="wrap_content"
  16. android:layout_height="wrap_content"
  17. android:background="@drawable/shape"
  18. />
  19. </linearlayout>
Strings.xml
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <resources>
  3. <string name="Hello">hello world, roundbuttondemoactivity! </string>
  4. <string name="app_name">roundbuttondemo</string>
  5. </Resources>
Roundbuttondemoactivity.java
  1. Package com.android.RoundButtonDemo.activity;
  2. Import android.app.Activity;
  3. Import Android.os.Bundle;
  4. Import Android.view.View;
  5. Import Android.view.View.OnClickListener;
  6. Import Android.widget.Button;
  7. Import Android.widget.Toast;
  8. Public class Roundbuttondemoactivity extends Activity {
  9. Button Roundbutton;
  10. @Override
  11. public void OnCreate (Bundle savedinstancestate) {
  12. super.oncreate (savedinstancestate);
  13. Setcontentview (R.layout.main);
  14. roundbutton= (Button) Findviewbyid (R.id.roundbutton);
  15. //Use anonymous class to register button events
  16. Roundbutton.setonclicklistener (new Onclicklistener ()
  17. {
  18. public void OnClick (View v)
  19. {
  20. Toast.maketext (roundbuttondemoactivity.  This, "You clicked the Fillet button", Toast.length_long). Show ();
  21. }
  22. });
  23. }
  24. }
:

This article is from the "It Drip" blog, please be sure to keep this source http://liangruijun.blog.51cto.com/3061169/630051

Android Development Learning Note: Rounded button

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.