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