Android Basic Component Button

Source: Internet
Author: User

Android provides the normal button Buttton and Picture button ImageButton Two button components, ImageButton button has a Android:src property, used to set the background image of the button. You can add the Android:onclick property to the button's XML layout and then set the Listener event in Java code based on the button's ID.

Import Android.app.activity;import android.os.bundle;import Android.view.view;import Android.widget.Button;import Android.widget.imagebutton;import Android.widget.toast;public class Mainactivity extends Activity {private Button btn; Private ImageButton imagebtn; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.activity_main); btn= (Button) Findviewbyid (R.id.button1); ImageBtn= ( ImageButton) Findviewbyid (r.id.imagebutton1);} public void Myclick (view view) {switch (View.getid ()) {case R.id.button1:toast.maketext (mainactivity.this, "Normal button is clicked", (). Show (), Case R.id.imagebutton1:toast.maketext (mainactivity.this, "Picture button is clicked", ". Show ();}}}

  

Android Basic Component Button

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