EditText limit in Android can only enter phone number letter email address

Source: Internet
Author: User

The following is an example of a number, a telephone to tell EditText how to set the input type, other types can refer to the InputType class.

1) can only enter the number

The code is as follows Copy Code

EditText et = (edittext) Findviewbyid (r.id.ettest);
Et.setinputtype (Inputtype.type_class_number);

2) can only enter the phone number

The code is as follows Copy Code

EditText et = (edittext) Findviewbyid (r.id.ettest);
Et.setinputtype (Inputtype.type_class_phone);//Telephone

3) e-mail address

The code is as follows Copy Code

EditText et = (edittext) Findviewbyid (r.id.ettest);
Et.setinputtype (inputtype.type_text_variation_email_address);

4) prohibit the entry of any text

The code is as follows Copy Code

EditText et = (edittext) Findviewbyid (r.id.ettest);
Et.setinputtype (Inputtype.type_null);

Prohibit input (not eject input method) The above is also a way to hide the input method, there is another hidden way,

To view the Android Hidden IME (IME) input box

There are two ways to not allow the program to rise by default IME input box:
1. Let EditText lose focus, use EditText Clearfocus method
2. Force hides the Android Input Method window, in the IME class we instantiate the input method to control the object, through Hidesoftinputfromwindow to hide the IME input box.

Code

The code is as follows Copy Code
Toast.maketext (Windowbackgroundcoloractivity.this, "Focus Change", Toast.length_short). Show ();
Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service);
The first of these methods
Imm.togglesoftinput (inputmethodmanager.show_implicit, inputmethodmanager.hide_not_always);
The second method
Imm.hidesoftinputfromwindow (V.getwindowtoken (), inputmethodmanager.hide_not_always);

Reference code:

  code is as follows copy code

< EditText android:id= "@+id/ettest" android:inputtype= "number"
       android: Layout_width= "Wrap_content"
       android:layout_height= "Wrap_content"/>

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.