TextView and EditText of Android controls
TextView: Display text box control
EditText: Enter text box
Common properties of TextView and EditText
Common Properties for TextView controls
Android:id the ID of the control
Android:layout_width width of the control
Android:layout_height height of the control
Android:text text content
Android:textsize Text Size
Android:textcolor text color
Android:background Control Background
The Common properties of EditText , in addition to the same common properties as TextView, include:
Android:hint input Hint text
Android:inputtype Input Text Type
Insert TextView and edittext information in main_activity:
Wrap_content: Wrapping the actual text content
Match_parent: The current control fills the parent class container: A property value added after 2.3api
Fill_parent: The current control fills the parent class container: A property value before 2.3api
TextView:
< TextView Android:layout_width = "Wrap_content" android:layout_height= "Wrap_content" android:text= "Name:" android:textsize = "28SP" android:textcolor= "#00FF00" />
EditText:
< EditText Android:hint = "Please enter your name" android:id= "@+id/edittext1" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" >
<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= "Com.example.textviewedittext.mainactivity$placeholderfragment"android:orientation= "Horizontal" > <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Name:"android:textsize= "28SP"Android:textcolor= "#00FF00" /> <EditTextAndroid:hint= "Please enter your name"Android:id= "@+id/edittext1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" > <Requestfocus/> </EditText></LinearLayout>
Fragment_main.xml
< framelayout xmlns:android = "http://schemas.android.com/apk/res/android" Xmlns:tools = "Http://schemas.android.com/tools" Android:id = "@+id/container" Android: Layout_width = "Match_parent" Android: Layout_height = "Match_parent" tools: Context = "com.example.textviewedittext.MainActivity" Tools:ignore = "Mergerootframe" />
activity_main.xml (no changes)
PackageCom.example.textviewedittext;Importandroid.support.v7.app.ActionBarActivity;ImportAndroid.support.v7.app.ActionBar;Importandroid.support.v4.app.Fragment;ImportAndroid.os.Bundle;ImportAndroid.view.LayoutInflater;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;ImportAndroid.os.Build; Public classMainactivityextendsactionbaractivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); if(Savedinstancestate = =NULL) {Getsupportfragmentmanager (). BeginTransaction (). Add (R.id.container,Newplaceholderfragment ()). commit (); }} @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; } @Override Public Booleanonoptionsitemselected (MenuItem item) {//Handle Action Bar item clicks here. The Action Bar would//automatically handle clicks on the Home/up button, so long//As you specify a the parent activity in Androidmanifest.xml. intID =Item.getitemid (); if(id = =r.id.action_settings) { return true; } return Super. onoptionsitemselected (item); } /*** A placeholder fragment containing a simple view. */ Public Static classPlaceholderfragmentextendsFragment { Publicplaceholderfragment () {} @Override PublicView Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) { View Rootview= Inflater.inflate (R.layout.fragment_main, container,false); returnRootview; } }}
Mainactivity.java (no changes)
Effect:
Android displays and enters text messages in the interface TextView and EditText