Step-by-step _android Development Course [17]_ User interface button

Source: Internet
Author: User

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

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.