ANDROID04-UI01 Common Controls

Source: Internet
Author: User

1. Use of common controls:

Textviewbuttonedittextimageview1.TextView
<textview            android:id= "@+id/text_view"            android:layout_width= "match_parent"            android:layout_height = "Wrap_content"            android:text= "This is TextView"/>

ANDROID:LAYOUT_WIDTH Specifies the width of the control

Android:layout_height Specifies the height of the control

All controls in Android have these two properties, with selectable values of three match_parent, Fill_parent, and wrap_content (size consistent with content)

android:gravity= "Center" text alignment

Android:textsize= "24SP" Font size

Android:textcolor= "#00ff00" Font Color

2.Button

<button            android:id= "@+id/button"            android:layout_width= "match_parent"            android:layout_height= " Wrap_content "            android:text=" button "/>

Register Listener

1.//Anonymous class methods
Button = (button) Findviewbyid (R.id.button); Button.setonclicklistener (New Onclicklistener () { @Override public void OnClick (View v) {//Add logic here}});
2.//Implementation Interface Onclicklistener

public class Mainactivity extends Activity implements Onclicklistener {

        Private button button;
        @Override        protected void onCreate (Bundle savedinstancestate) {
        
        Setcontentview (R.layout.activity_main);
        
        Button.setonclicklistener (this);}
        @Override public        void OnClick (View v) {
            Switch (V.getid ()) {case            r.id.button://adds logic here
                break;            Default
Break }
}
}

  

3.EditText

Controls that allow you to enter and edit content in a control

<edittext            android:id= "@+id/edit_text"            android:layout_width= "match_parent"            android:layout_ height= "Wrap_content"
Suggestive text
            android:hint= "Type something Here"/>
            />
The Android:maxlines property can specify the maximum number of rows to display

Get input from EditText

Gets the EditText object that calls the EditText object's GetText (). ToString () method ImageView Controls for displaying pictures android:src property specifies a picture resource
<imageview            android:id= "@+id/image_view"            android:layout_width= "wrap_content"            android:layout_ height= "Wrap_content"            android:src= "@drawable/ic_launcher"            />

Dynamically change the picture in ImageView by code

Imageview.setimageresource (R.drawable.jelly_bean);

ProgressBar

ProgressBar is used to display a progress bar on the interface, indicating that our program is loading some data.

  

ANDROID04-UI01 Common Controls

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.