Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305
- Topic: Button for user interface
button and ImageButton control instances:
Activity_main.xml Source code:
<?xml version= "1.0" encoding= "Utf-8"?><linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" android:orientation =" vertical " android:layout_width = "fill_parent" android:layout_height = "fill_parent" ; <button android:id = "@+id/btn" android:layout_height =< Span class= "Hljs-value" > "wrap_content" android:layout_width = "wrap_content" android:text =" I am button "/> <ImageButtonandroid:id="@+id/imgbtn"android:layout_height="Wrap _content "android:layout_width=" Wrap_content "android:src=" @drawable/myimage " /> </linearlayout>
A listener event that instantiates it in Mainactivity.java and adds a button click:
Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.ImageButton; Public class mainactivity extends Activity { PrivateButton btn;PrivateImageButton imgbtn;@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main);//instantiation of EditTextBTN = (Button) Findviewbyid (R.ID.BTN); IMGBTN = (ImageButton) Findviewbyid (R.ID.IMGBTN); Btn.setonclicklistener (NewOnclicklistener () {@Override Public void OnClick(View arg0) {//TODO auto-generated method stubLOG.V ("------------","I'm a button."); } }); Imgbtn.setonclicklistener (NewOnclicklistener () {@Override Public void OnClick(View arg0) {//TODO auto-generated method stubLOG.V ("------------","I'm ImageButton."); } }); }}
Operation Result:
Click the first button:
Logcat window Display
Click the second button:
Logcat window Display
Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305
Step-by-step _android Development Course [17]_ User interface button