Textview, editview, and checkbox of Android Control

Source: Internet
Author: User

AndroidControls: textview, editview, and checkbox

-- Study Note 3 (Jin haijian)

Purpose:Use a login box to learn how to use textview, editview, and checkbox.

Create a project and design the following UI

Main. xml layout code

 

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout Android: Id = "@ + ID/linearlayout01" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" xmlns: Android = "http://schemas.android.com/apk/res/android" Android: orientation = "vertical"> <br/> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "@ string/username" Android: id = "@ + ID/password"> </textview> <br/> <edittext Android: layout_height = "wrap_content" Android: Id = "@ + ID/editpassword" Android: layout_width = "match_parent"> </edittext> <br/> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: id = "@ + ID/username" Android: text = "@ string/password"> </textview> <br/> <edittext Android: layout_height = "wrap_content" Android: id = "@ + ID/editpassword" Android: layout_width = "fill_parent"> </edittext> <br/> <checkbox Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: Id = "@ + ID/checkremenber" Android: text = "@ string/remenber"> </checkbox> <br/> <button Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: Id = "@ + ID/login" Android: TEXT = "@ string/lonin"> </button> <br/> </linearlayout> <br/> 

 

 

Textview

Set username to white, font size to 20, and bold

Set Password color to white and font to 18

 

M_username = (textview) This. findviewbyid (R. id. username); <br/> m_password = (textview) This. findviewbyid (R. id. password); <br/> m_username.settextsize (18); <br/> m_password.settextsize (20); </P> <p> // set the color, use color RGB Settings <br/> // m_username.settextcolor (color. RGB (0xff, 0xff, 0xff); <br/> // use the color built-in color <br/> // m_username.settextcolor (color. white); <br/> // you can use the getcolor method of getresources to obtain <br/> m_username.settextcolor (this. getresources (). getcolor (R. color. usernamecolor); <br/> typeface tyface = typeface. create ("", typeface. bold); <br/> m_username.settypeface (tyface); </P> <p> m_password.settextcolor (this. getresources (). getcolor (R. color. usernamecolor); <br/> m_password.settypeface (tyface); <br/> 

Editview

Set the username prompt to "Enter the user name". You can only enter numbers.

Set the password prompt to "Enter Password", set the attribute to the Password attribute, set only numbers can be entered

Prompt call

M_editusername.sethint ("Enter the user name ");

M_editpassword.sethint ("enter the password ");

You can only enter numbers in settings. There are three methods:

Method 1: directly generate the digitskeylistener object.

M_editusername.setkeylistener (New digitskeylistener (false, true ));

Method 2: Set attributes in edittext

Android: inputtype = "Number"

 

Method 3: Create a char [] and add the characters that can be entered.

M_editusername.setkeylistener (New numberkeylistener () <br/> {<br/> char acceptnumber [] = {'1', '2', '3', '4 ', '5', '6', '7', '8', '9', '0'}; <br/> protected char [] getacceptedchars () {<br/> return acceptnumber; <br/>}< br/> Public int getinputtype () {<br/> return 0; <br/>}< br/> }); 

Button

Onclick event processing

M_btlogin.setonclicklistener (New button. onclicklistener () {<br/> Public void onclick (view v) {<br/> Toast = toast. maketext (login. this, "the user name is" + m_editusername.gettext () + "the PSD is" + m_editpassword.gettext (), toast. length_long); <br/> toast. show (); <br/>}< br/> }); 

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.