When we click in the EditText provided by Android, we will automatically eject the soft keyboard, in fact, the control of the soft keyboard can be achieved by Inputmethodmanager this class. The way we need to control the soft keyboard is that two kinds of one are like edittext when the OnClick event occurs when a soft keyboard appears, and when a program is opened automatically pop-up soft keyboard.
Public classInputmethodmanagertest extends Activity implements onclicklistener{Privatebutton button; @Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stubsuper.oncreate (savedinstancestate); LinearLayout Layout=NewLinearLayout ( This); Linearlayout.layoutparams Layoutparams=NewLinearlayout.layoutparams (linearlayout.layoutparams.wrap_content,linearlayout.layoutparams.wrap_content); Button=NewButton ( This); Button.setid (123); Button.settext ("Hello Gaomatrix"); Button.setonclicklistener ( This); Layout.addview (button, layoutparams); Setcontentview (layout); /** Use a timer to control when you open the activity, a soft keyboard appears*/Timer Timer=NewTimer (); Timer.schedule (NewTimerTask () {@Override Public voidrun () {Inputmethodmanager Inputmethodmanager=(Inputmethodmanager) Getsystemservice (Context.input_method_service); Inputmethodmanager.togglesoftinput (0, inputmethodmanager.hide_not_always); } }, -); } /** * Trigger display soft keyboard when clicking Event*/@Override Public voidOnClick (View v) {Inputmethodmanager Inputmethodmanager=(Inputmethodmanager) Getsystemservice (Context.input_method_service); Inputmethodmanager.togglesoftinput (0, inputmethodmanager.hide_not_always); }
The explanation in the API for the Togglesoftinput method inside this Inputmethodmanager class is: This method toggles the Input Method window display. If the input window is already displayed, it gets hidden. If not the input window would be displayed. This method in the interface to switch the function of the input method, if the input method out of the real state, he will hide, if in a hidden state, display input method. For the second way into the activity, the soft keyboard is automatically displayed, in a timer, that is, executed in a thread, but only for a delay of 2 seconds, because the Android program in the OnCreate function does not complete the screen drawing.
Of course we can also control the display and hiding of the soft keyboard separately
// Show Inputmethodmanager IMM = (inputmethodmanager)this. Getsystemservice (Context.input_method_service); 0 ); // Hidden 0
The view in the code above is the view of the event when the button is clicked, or the layout of the activity as a whole (the test of the idiot can run normally)
There are two other keyboard controls that are often used:
1. Edittext.setimeoptions (EDITORINFO.IME_FLAG_NO_EXTRACT_UI); When you click EditText, a full screen input window will not pop up
2.edittext.setinputtype (Inputtype.type_null); When you click EditText, the soft keyboard is shielded
Call the soft keyboard in Android