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