showSoftInput()
doesn\'t show the keyboard for me, but toggleSoftInput()
does. I saw some other post that said to disable the hard keyboard when us
public void hideKeyboard() {
myTextView.setFocusable(true);
myTextView.setFocusableInTouchMode(true);
imm.hideSoftInputFromWindow(myTextView.getWindowToken(), 0);
}
WORKS
public void hideKeyboard() {
imm.hideSoftInputFromWindow(myTextView.getWindowToken(), 0);
}
DOES NOT WORK
imm is dealt with earlier as I am using a Fragment so:
Declare imm in the Fragment
private InputMethodManager imm;
Then in the fragment add:
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
imm = (InputMethodManager)
getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
}
He says after 3 to 4 hours of research and failures !!
Thanks user_CC ! :-)
Phil
Try this:
public void showTheKeyboard(Context context, EditText editText){
InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
If this doesn't work read the tutorial from here
I know this post is pretty old, but for those who came for answers from this date and none of the above worked. The code below worked for me on an Activity when an Alert Dialog popped up.
InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
to show keyboard:
keyboard.toggleSoftInput(editText.getPaintFlags(), 0);
to hide keyboard:
keyboard.hideSoftInputFromWindow(editText.getWindowToken(), 0);
The precise answer to this question why does showSoftInput doesnt work and toggleSoftInput does?
Is that the View to which you are trying to display the Keyboard doesn't have the focus. So to solve this problem and to use the method showSoftInput you will have to call the following to methods on your view:
setFocusable(true);
setFocusableInTouchMode(true);
Calling the above methods will make sure that when you click on the View retains and captures the focus.
showSoftInput() does not work when device has a hard (slide-out) keyboard
Android show softkeyboard with showSoftInput is not working?
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... !