1. // hide the keyboard
(InputMethodManager) getSystemService (INPUT_METHOD_SERVICE). hideSoftInputFromWindow (WidgetSearchActivity. this. getCurrentFocus (). getWindowToken (), InputMethodManager. HIDE_NOT_ALWAYS );
2. // display the soft keyboard. The control ID can be EditText or TextView.
(InputMethodManager) getSystemService (INPUT_METHOD_SERVICE). showSoftInput (Control ID, 0 );
3. Do not automatically pop up the keyboard:
If the EditText control is used, the focus is automatically displayed for the first time, and the keyboard is displayed. If you do not want to automatically display the keyboard, you can use either of the following methods:
Method 1: Set the corresponding activity in the mainfest File
Android: windowSoftInputMode = "stateHidden" or android: windowSoftInputMode = "stateUnchanged ".
Method 2: You can place a hidden TextView in the layout and requsetFocus during onCreate.
Note that do not set Visiable = gone for TextView; otherwise, it will become invalid.
You can put a hidden TextView in the layout and requsetFocus during onCreate.
Note that do not set Visiable = gone for TextView; otherwise, it will become invalid.
<TextView
Android: id = "@ + id/text_notuse"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: focusable = "true"
Android: focusableInTouchMode = "true"
/>
TextView textView = (TextView) findViewById (R. id. text_notuse );
TextView. requestFocus ();