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