Android 0 Basics Section 18th: EditText properties and how to use them

Source: Internet
Author: User
Tags time and date

EditText is very similar to TextView, and it even shared most of the XML attributes and methods with TextView. The biggest difference between EditText and TextView is that EditText can accept user input.

I. Introduction of EDITTEXT

EditText supported XML attributes and related methods see the input-related properties and methods described in the TextView table, one of the more important properties is InputType, which is used to set the input type for edittext, and its property values are mainly as follows.

  • Android:inputtype=none: normal characters.
  • Android:inputtype=text: normal characters.
  • Android:inputtype=textcapcharacters: Uppercase letters.
  • Android:inputtype=textcapwords: Capitalize first letter.
  • Android:inputtype=textcapsentences: Only the first letter is capitalized.
  • Android:inputtype=textautocorrect: Auto-complete.
  • Android:inputtype=textautocomplete: Auto-complete.
  • Android:inputtype=textmultiline: Multiple lines of input.
  • Android:inputtype=textimemultiline: Input method multiple lines (if supported).
  • Android:inputtype=textnosuggestions: not prompt.
  • Android:inputtype=texturi: URL.
  • Android:inputtype=textemailaddress: E-mail address.
  • Android:inputtype=textemailsubject: Message subject.
  • Android:inputtype=textshortmessage: SMS.
  • Android:inputtype=textlongmessage: Long message.
  • Android:inputtype=textpersonname: Names.
  • Android:inputtype=textpostaladdress: Address.
  • Android:inputtype=textpassword: Password.
  • Android:inputtype=textvisiblepassword: visible password.
  • Android:inputtype=textwebedittext: Text as a Web form.
  • Android:inputtype=textfilter: Text filtering filtering.
  • android:inputtype=textphonetic: Pinyin input.
  • Android:inputtype=number: Numbers.
  • Android:inputtype=numbersigned: Signed number format.
  • Android:inputtype=numberdecimal: Floating-point format with decimal point.
  • Android:inputtype=phone: dial pad.
  • Android:inputtype=datetime: Time and date.
  • Android:inputtype=date: Date keyboard.
  • Android:inputtype=time: Time keyboard.

EditText also derives the following two subclasses.

    • Autocompletetextview: EditText with auto-complete function. Because this class usually needs to be used in conjunction with adapter, it will be learned in the next chapter.
    • Extractedittext: Not the UI component, but the underlying service class of the EditText component, which is responsible for providing full-screen input method support.

Ii. Examples of EditText

Next, a simple example program is used to learn the common uses of edittext.

Continue to use the Widgetsample project created in the previous period to create a Edittext_layout.xml file under the app/main/res/layout/directory.

Select Layout, right-click popup menu, select New---XML---layout XML file, or select layout resource file, or select layout to complete via the File menu or the new icon As shown in the following:

The XML File creation page appears as shown in:

In Layout File name, enter the name "Edittext_layout" and click "Finish" to complete the creation. Then populate it with the following code snippet:

<?XML version= "1.0" encoding= "Utf-8"?>  <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical">        <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "User name:"android:textsize= "16SP"/>      <EditTextAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Please enter user name" />        <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Password:"android:textsize= "16SP"/>      <!--android:inputtype= "Numberpassword" indicates that only digital passwords can be accepted -      <EditTextAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Please enter password"Android:inputtype= "Numberpassword"/>        <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Age:"android:textsize= "16SP"/>      <!--inputtype= "Number" indicates a value input box -      <EditTextAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Please enter age"Android:inputtype= "Number"/>        <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Birthday:"android:textsize= "16SP"/>      <!--inputtype= "Date" indicates that it is a day input box -      <EditTextAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Please enter your Birthday"Android:inputtype= "Date"/>        <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Phone number:"android:textsize= "16SP"/>      <!--inputtype= "Phone" indicates an input box for entering a phone number -      <EditTextAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Please enter phone number"Android:inputtype= "Phone"/>    </LinearLayout>  

The first text box in the upper interface layout specifies the prompt for the text box via Android:hint: Enter the user name-this is the default hint for the text box. This message is displayed by default in the text box when the user has not entered it;

The second input box through Android:inputtype=numberpassword "Setting this is a password box, and can only accept the numeric password, the user in the text box input characters will be replaced by dots;

The third input box is set to an input box that accepts only numeric values via Android:inputtype=number;

The fourth input box specifies that it is a date input box by android:inputtype= date;

The fifth input box is set to a phone Number entry box via android:inputtype= phone.

Then modify the App/src/java/mainactivity.java file to load the layout file as a new Edittext_layout.xml file, the modified code is as follows:

 Public class extends appcompatactivity {        @Override      protectedvoid  onCreate (Bundle Savedinstancestate) {          super. OnCreate (savedinstancestate);          Setcontentview (r.layout.edittext_layout);      }  }  

Running the program, you can see the interface effect shown.

EditText's sample program is here first, and it is recommended that you do your own exercises for other use methods.

Come here today, the next issue begins the UI component learning. If you have questions welcome message together to explore, also welcome to join the Android 0 Basic introductory Technology discussion group, grow together!

Past period Summary share:

Android 0 Basics Introduction 1th: Android's past life

Android 0 Basics Section 2nd: Android system Architecture and application components those things

Android 0 Basics Section 3rd: Bring you up to talk about Android development environment

Android 0 Basics 4th: Installing and configuring the JDK correctly Ko fu the first trick

Android 0 Basics 5th: Use ADT bundles to easily meet the goddess

Android 0 Basics 6th: Configuration Optimization SDK Manager, official dating goddess

Android 0 Basics 7th: Take care of Android simulator and start the Sweet journey

Android 0 Basics 8th: HelloWorld, the starting point for my first trip

Android 0 Basics 9th: Android app, no code can be developed

Android 0 Basics Section 10th: Development IDE Big upgrade, finally ushered in Android Studio

Android 0 Basics Introductory Section 11th: Simple steps to take you to fly, run Android Studio project

Android 0 Basics 12th: Get familiar with the Android studio interface and start selling

Android 0 Basics 13th: Android Studio Configuration optimization to create a development tool

Android 0 Basics 14th: Using high-speed genymotion, stepping into the rocket era

Android 0 Basics Section 15th: Mastering the Android Studio project structure, sailing

Android 0 Basics Section 16th: Android User Interface Development overview

Android 0 Basics Section 17th: TextView Properties and Methods Daquan

This article copyright for the public Share talent show (Shareexpert)--Xin 鱻 all, if reproduced please note source, hereby declare!

Android 0 Basics Section 18th: EditText properties and how to use them

Related Article

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.