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"/> |