Home > Java > javaTutorial > body text

Analyze the implementation method of hiding and displaying the soft keyboard and not automatically popping up the keyboard in Android

高洛峰
Release: 2017-01-07 12:58:37
Original
1484 people have browsed it

1. //Hide the soft 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, TextView

((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).showSoftInput(control ID, 0);

3. Do not automatically pop up the keyboard:

With the EditText control, it will automatically gain focus and pop up the keyboard when it is displayed for the first time. If you do not want the keyboard to pop up automatically, there are two options Method one:

Method 1: Set the corresponding activity in the mainfest file

android:windowSoftInputMode="stateHidden" or android:windowSoftInputMode="stateUnchanged".

Method 2: You can put a hidden TextView in the layout, and then requsetFocus during onCreate.

Note that TextView should not set Visiable=gone, otherwise it will be invalid.

You can put a hidden TextView in the layout, and then requsetFocus during onCreate.

Note TextView. Do not set Visiable = gone, otherwise it will fail

# & lt; 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();


For more analysis on how to hide and display the soft keyboard and not automatically pop up the keyboard in Android, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!