Android-EditText, android-edittext
EditText is a direct subclass of TextView. It differs from TextView in that EditText can be input by users.
The following example is used to describe the usage of EditText.
Example: log on to sina Weibo (note that we have not touched the buttons and image controls, so we use TextView for the image in the pop-up box)
First, check the sina Weibo login page
Because it was taken from my iphone, the background of sina Weibo's android version is not this one, so I changed the background image.
The Code is as follows:
1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" 3 android: layout_width = "match_parent" 4 android: layout_height = "match_parent" 5 android: background = "@ drawable/login_wallpaper1" 6 android: orientation = "vertical"> 7 8 <! -- User profile picture --> 9 10 <TextView11 android: layout_width = "wrap_content" 12 android: layout_height = "wrap_content" 13 android: layout_gravity = "center_horizontal" 14 android: layout_marginBottom = "10dp" 15 android: layout_marginTop = "20dp" 16 android: background = "@ drawable/login_profile_default"/> 17 <! -- Enter the username and password and use the nested layout --> 18 19 <LinearLayout20 android: layout_width = "match_parent" 21 android: layout_height = "wrap_content" 22 android: layout_margin = "10dp" 23 android: background = "@ drawable/fast_select_merchant_input_bg" 24 android: orientation = "vertical"> 25 26 <EditText27 android: id = "@ + id/et_user" 28 android: layout_width = "match_parent" 29 android: layout_height = "wrap_content" 30 android: background = "@ null" 31 Ndroid: drawableLeft = "@ drawable/login_user" 32 android: drawablePadding = "15dp" 33 android: hint = "email/mobile phone number" 34 android: padding = "10dp"/> 35 <! -- Split line --> 36 37 <View38 android: layout_width = "match_parent" 39 android: layout_height = "1dp" 40 android: background = "@ android: color/darker_gray "/> 41 42 <EditText43 android: id =" @ + id/et_pwd "44 android: layout_width =" match_parent "45 android: layout_height =" wrap_content "46 android: background = "@ null" 47 android: drawableLeft = "@ drawable/login_key" 48 android: drawablePadding = "15dp" 49 android: hint = "enter the password" 50 android: InputType = "textPassword" 51 android: padding = "10dp"/> 52 </LinearLayout> 53 <! -- Simulate logon button --> 54 55 <TextView56 android: layout_width = "match_parent" 57 android: layout_height = "wrap_content" 58 android: layout_margin = "10dp" 59 android: background = "#006400" 60 android: gravity = "center" 61 android: padding = "10dp" 62 android: text = "login" 63 android: textColor = "# F8F8FF" 64 android: textSize = "30sp"/> 65 66 </LinearLayout>View Code
The layout can be nested. On this login page, the input box section is nested with a linear layout.
You can preview the results.
How to receive content input from the edit text control in android
EditText editText = (EditText) findViewById (R. id. ***); // The premise is that you have registered the control in the layout file. *** it is the id of the registered control.
String s = editText. getText (). toString (); // The content entered in the text box is stored in variable s.
How does android obtain the data of the edit text control in the pop-up dialog box?
First obtain the dialog, then find the edit text control, and finally obtain the control data according to the edittext. getText method.