Reprint: Linux community
1> keyboard status-hide or display.
I. the keyboard is automatically displayed.
- Timer timer = new timer ();
- Timer. Schedule (New timertask (){
- Public void run (){
- Inputmethodmanager = (inputmethodmanager) getsystemservice (context. input_method_service );
- Inputmethodmanager. togglesoftinput (0, inputmethodmanager. hide_not_always );
- }
- },2000 );
Ii. Soft Keyboard
Set in activity:
Android: windowsoftinputmode = "stateunspecified". Default setting: the keyboard status (hidden or visible) is not specified. The system selects an appropriate status or topic-dependent setting. "Stateunchanged", the keyboard is in the last state. "Statehidden". When you select this activity, the keyboard is hidden. "Statealwayshidden", the keyboard is always hidden. "Statevisible",. the soft keyboard is visible. "Statealwaysvisible". When you select this activity, the keyboard is visible. "Adjustunspecified",. it is not specified whether the activity main window is adjusted to set aside space for the soft keyboard, or whether the content on the window gets the current focus on the screen to be visible. The system automatically selects one of these modes, depending on whether the content of the window has any layout view that can scroll their content. If there is such a view, the window will be adjusted. This assumption can make the content of the scrolling window visible in a small area. This is the default behavior settings for the main window. That is to say, the system automatically determines whether to adopt the translation mode or the compression mode, and determines whether the content can be rolled. "Adjustresize", (compression mode) when the keyboard pops up, adjust the screen size for the main window to leave space for the keyboard. "Adjustpan"]> (translation mode: when the input box is not blocked, the layout is not adjusted. However, when the input box is to be blocked, the window is translated. That is to say, this mode always keeps the input box visible...
3. Hide the keyboard:
Edittext edit = (edittext) findviewbyid (R. Id. Edit );
Inputmethodmanager Imm = (inputmethodmanager) getsystemservice (context. input_method_service );
Imm. hidesoftinputfromwindow (edit. getwindowtoken (), 0 );
4. The edittext keyboard is not displayed by default.
Method 1:
In androidmainfest. XML, select the activity and set the windowsoftinputmode attribute to adjustunspecified | statehidden.
Example: <Activity
Android: Name = ". Main"
Android: Label = "@ string/app_name"
Android: windowsoftinputmode = "adjustunspecified | statehidden"
Android: configchanges = "orientation | keyboardhidden">
<Intent-filter>
<Action
Android: Name = "android. Intent. Action. Main"/>
<Category
Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
Method 2:
Defocus edittext. Use the clearfocus method of edittext.
For example, edittext edit = (edittext) findviewbyid (R. Id. Edit );
Edit. clearfocus ();
Method 3:
Force hide Android Input Method window
For example, edittext edit = (edittext) findviewbyid (R. Id. Edit );
Inputmethodmanager Imm = (inputmethodmanager) getsystemservice (context. input_method_service );
Imm. hidesoftinputfromwindow (edit. getwindowtoken (), 0 );
5. edittext always does not bring up the software keyboard
Example: edittext edit = (edittext) findviewbyid (R. Id. Edit );
Edit. setinputtype (inputtype. type_null );