How to hide and display a soft keyboard and a non-automatically pop-up keyboard in android

Source: Internet
Author: User

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

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.