Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android softkeyboard showSoftInput vs toggleSoftInput

Tags:

android

showSoftInput() doesn't show the keyboard for me, but toggleSoftInput() does. I saw some other post that said to disable the hard keyboard when using the emulator, but I'm not using an emulator. I'm loading my APK on an actual device with no hard keyboard. Shouldn't both methods work? Why doesn't showSoftInput() work? I would like to explicitly associate the keyboard with a specific text field.

Doesn't work:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); editText.setText("textchange"); //i see the text field update imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED); 

Works:

InputMethodManager imm = (InputMethodManager) getDelegate().getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0); 
like image 982
prostock Avatar asked Dec 04 '12 02:12

prostock


People also ask

What is soft input mode Android?

The Android system shows an on-screen keyboard—known as a soft input method—when a text field in your UI receives focus.

What is input method manager in Android?

android.view.inputmethod.InputMethodManager. Central system API to the overall input method framework (IMF) architecture, which arbitrates interaction between applications and the current input method.

How do I hide the keyboard on my Android?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow , passing in the token of the window containing your focused view. This will force the keyboard to be hidden in all situations. In some cases you will want to pass in InputMethodManager.


2 Answers

Show Keyboard + focus and also if you want to Hide the keyboard

@Override public void onResume () {     super.onResume();      inputSearch.setFocusableInTouchMode(true);     inputSearch.requestFocus();      // Show Keyboard     InputMethodManager imm = (InputMethodManager) getSherlockActivity().getSystemService(             Context.INPUT_METHOD_SERVICE);     imm.showSoftInput(inputSearch, InputMethodManager.SHOW_IMPLICIT); } 

P.S inputSearch = (EditText) getSherlockActivity().findViewById(R.id.inputSearch);

    // Hide Keyboard InputMethodManager imm = (InputMethodManager) getSherlockActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(inputSearch.getWindowToken(), 0); 
like image 25
Mazen Kasser Avatar answered Oct 30 '22 12:10

Mazen Kasser


It seems that the keyboard is initially displayed but hidden by something else, because the following works (but is actually a dirty work-around):

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); editText.postDelayed(new Runnable() {     @Override     public void run()     {         editText.requestFocus();         imm.showSoftInput(editText, 0);     } }, 100); 

And when looking at logcat I suspect the cause behind this message hides the keyboard initially shown:

Hide Clipboard dialog at Starting input: finished by someone else... !

like image 89
Bert Regelink Avatar answered Oct 30 '22 13:10

Bert Regelink