Android Control--textview,edittext

Source: Internet
Author: User

TextView:

Display text controls

EditText

Enter text box

1.TextView Common Properties:

2.EditText Common Properties:

Set the Android:inputtype property of the EditText to restrict the type of text input such as android:inputtype= "Textpassword" to set the input format as a cipher, android:inputtype= "phone "To set the input format for the dial pad

3. Using TextView and EditText

Layout file:

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context=". Mainactivity " >    <!--wrap_content: Wrapping the actual text content "Match_parent": Full parent container, linearlayout as parent container (a property after 2.3API) Fill-parent: Fill the parent container, Linearlay Out is a parent class container (a property before 2.3API) -    <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "User name:"Android:textcolor= "#000000"android:textsize= "28SP" />    <EditTextAndroid:id= "@+id/edittext1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:hint= "Please enter name"Android:ems= "Ten" >        <Requestfocus/>    </EditText></LinearLayout>

Java code

 PackageCom.example.mooc;ImportAndroid.os.Bundle;Importandroid.app.Activity;ImportAndroid.view.Menu; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //introduce the layout file to the activitySetcontentview (R.layout.activity_main); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; }}

Results:

Android Control--textview,edittext

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.