Analysis of Android hidden and display soft keyboard and do not automatically eject the keyboard implementation method _android

Source: Internet
Author: User

1.// Hide soft keyboard

((Inputmethodmanager) Getsystemservice (Input_method_service)). Hidesoftinputfromwindow ( WidgetSearchActivity.this.getCurrentFocus (). Getwindowtoken (), inputmethodmanager.hide_not_always);

2,// display soft keyboard , control ID can be edittext,textview

((Inputmethodmanager) Getsystemservice (Input_method_service)). Showsoftinput ( control ID, 0);

3, does not automatically eject the keyboard:

With the EditText control, the focus is automatically received the first time it is displayed, and thekeyboard pops up, and if you do not want to automatically eject the keyboard, there are two ways:

Method One: In the Mainfest file, set the corresponding activity

Android:windowsoftinputmode= "Statehidden" or android:windowsoftinputmode= "stateunchanged".

Method Two: Can put a hidden textview in the layout, then Requsetfocus when OnCreate.

Note TextView do not set visiable=gone, otherwise it will fail

, you can put a hidden TextView in the layout, and then Requsetfocus in the onCreate.

Note TextView do not set visiable=gone, otherwise it will fail

<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 ();

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.