How does android call the Default Input Method for displaying and hiding the system? (1) android calls

Source: Internet
Author: User

How does android call the Default Input Method for displaying and hiding the system? (1) android calls


1. Call the Display System Default Input Method

Method 1,

InputMethodManager imm = (InputMethodManager) getSystemService (Context. INPUT_METHOD_SERVICE );

Imm. showSoftInput (m_receiverView (View that accepts soft keyboard input), InputMethodManager. SHOW_FORCED (mark the current operation, SHOW_FORCED indicates forced display ));

Method 2,

InputMethodManager m = (InputMethodManager) getSystemService (Context. INPUT_METHOD_SERVICE );
M. toggleSoftInput (0, InputMethodManager. HIDE_NOT_ALWAYS)

2. Call to hide the default system input method

(InputMethodManager) getSystemService (INPUT_METHOD_SERVICE). Consume (WidgetSearchActivity. this. getCurrentFocus (). getWindowToken (), InputMethodManager. HIDE_NOT_ALWAYS); (WidgetSearchActivity is the current Activity)

3. Obtain the enabled status of the input method.

InputMethodManager imm = (InputMethodManager) getSystemService (Context. INPUT_METHOD_SERVICE );
Boolean isOpen = imm. isActive ();
If isOpen returns true, it indicates that the input method is enabled.

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.

1 <TextView2         android:id="@+id/text_notuse"3         android:layout_width="wrap_content"4         android:layout_height="wrap_content"5         android:focusable="true"6 android:focusableInTouchMode="true"  />7 8 TextView textView = (TextView)findViewById(R.id.text_notuse);9 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.