Tube and Android keypad hidden Summary

Source: Internet
Author: User

Reprint: Linux community

1> keyboard status-hide or display.

I. the keyboard is automatically displayed.

  1. Timer timer = new timer ();
  2. Timer. Schedule (New timertask (){

  3. Public void run (){
  4. Inputmethodmanager = (inputmethodmanager) getsystemservice (context. input_method_service );
  5. Inputmethodmanager. togglesoftinput (0, inputmethodmanager. hide_not_always );
  6. }
  7. },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 );

 

Related Article

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.