android button Buttons

Source: Internet
Author: User

the button control in Android directly inherits the TextView. , the display on the page is a rectangular shape. Basic properties of the control:

Android:id= "": Unique identification of the button.

Android:layout_width= "" and android:layout_height= ": In addition to the numerical value there are wrap_content(Adaptive),Fill_ the parent (populate the Parental control) and match_parent(populate the parent control).

Android:layout_torightof= "" The control is on the right side of the other control.

Android:layout_toleftof= "" The control is on the left side of the other control.

Android:layout_margin= "40SP": The control is surrounded by a set of specified space.

Android:background: Set the background, can be a picture, or it can be a pure color,

Android:layout_alignparentleft= "true": On the left side of the parent control,

Android:layout_alignparentxxxx= "": Refers to which position in the parent control.

There are several ways to add a listener event to a button.

mode one: In the properties of the button,android:onclick= "onclick": in the activity thatlaunches the page again , create the onclick method. Note: The return value of the method must be void, the permission must be public, the method name must be the same as the value of the Android:onclick property, and must also have a View The parameters of the type.

mode two: use Anonymous inner class. to get the object of the button in the corresponding Activity , use the Setonclicklistener method to add an event to the button.

For example: BUTTONBTN = (Button) Findviewbyid (R.ID.BTN);

Btn.setonclicklistener (Newonclicklistener ()

{

@Override

public void OnClick (View v)

{

Toast.maketext (Mainactivity.this, " button was clicked ", Toast.length_long). Show ();

}

});

mode three:Activity implements android.view.View.OnClickListener interface, overrides The publicvoid OnClick (View v) method. Then set the event to the button and Pass The This parameter to the Setonclicklistener .


This article is from the "JDK7 Environment Building" blog, please make sure to keep this source http://zzhhz.blog.51cto.com/7107920/1625917

android button Buttons

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.