简体   繁体   中英

Android soft keyboard showing problem

I'm trying to control soft keyboard using this:

((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
            .hideSoftInputFromInputMethod(filterText.getWindowToken(), 0);
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
            .showSoftInput(filterText, InputMethodManager.SHOW_IMPLICIT);

But nothing happens on the device when i call this code. What can cause such behavior?

If you have a

EditText mEditText;

then you should set:

InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText, InputMethodManager.SHOW_FORCED);

For a textview,

TextView mtextview;

you can set:

android:focusableInTouchMode="true"

android:inputType="text"

in the xml file. Upon clicking on the textview, you will pop up the keyboard.

I was having an issue where the soft keyboard was showing up when I first entered the activity and I didn't want it to. This was messing up my scrollview. I was able to keep if from doing this by setting the following in the manifest file in the activity that I was dealing with: android:windowSoftInputMode="stateHidden"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM