Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a button in android?

Tags:

Can anybody tell how to add a button in android?

like image 233
vijay Avatar asked Apr 21 '10 09:04

vijay


People also ask

What is a button in Android?

In Android applications, a Button is a user interface that is used to perform some action when clicked or tapped. It is a very common widget in Android and developers often use it.

How do you add a button to aide?

Add a Button In order to do this add an XML Button element to the XML file. You need to specify the button's layout width and height. Choose "wrap_content", which means the view will be sized to exactly match the button's required content size. Also specify a layout margin and the button's text.


1 Answers

Check this Android Button tutorial; this simple example creates a Close Button.

All you need to do is:

1.Add Button widget to your Layout

<Button android:id="@+id/close"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:layout_alignParentBottom="true"     android:text="@string/title_close" /> 

2.Attach a setOnClickListener method to the button instance:

protected void onCreate(Bundle savedInstanceState) {   this.setContentView(R.layout.layoutxml);   this.closeButton = (Button)this.findViewById(R.id.close);   this.closeButton.setOnClickListener(new OnClickListener() {     @Override     public void onClick(View v) {       finish();     }   }); } 
like image 188
systempuntoout Avatar answered Sep 29 '22 05:09

systempuntoout