Show soft keyboard for dialogue

I am showing a dialog with an edittext view. However, the soft keyboard will open only if the user clicks on the edit. So I tried calling InputMethodManager with the following code.

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(dialogField,0); 

The dialog box is an input field. However, when should I do this? I tried it in the onStart () method of the dialog, but nothing happens. I also tried to request focus for dialogField before, but that doesn't change anything.

I also tried this code

 dialogField.setOnFocusChangeListener(new View.OnFocusChangeListener() { public void onFocusChange (View v, boolean hasFocus) { if (hasFocus) { Main.log("here"); dialogInput.getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); /* InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); mgr.showSoftInput(dialogField,0); */ } } }); 

in both versions. But no soft keyboard would like to appear. Main.log is just a log that shows me that the function is actually called. And yes, that’s called.

I can get the keyboard with the symbol SHOW_FORCED before opening the dialog box. But then it will not close when exiting. And I can do this only before I show the dialogue. Inside any callbacks this doesn't work either.

+47
android android-softkeyboard
Nov 23 '10 at 16:56
source share
3 answers

An amazing question, I also tried to do this and found a solution.

Using the AlertDialog.Builder dialog box AlertDialog.Builder you will need to invoke the dialog box as follows:

 AlertDialog.Builder builder = new AlertDialog.Builder(); AlertDialog dialog; builder.set... dialog = builder.create(); dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); dialog.show(); 

It worked for me.

Note: you must import android.view.WindowManager.LayoutParams; for a constant value.

+123
Oct 24 '13 at 17:53
source share
β€” -

try it

 InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(edttxt.getWindowToken(), 0); 

To close

 InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(edttxt.getWindowToken(), 0); 
-one
Mar 30 '16 at 11:14
source share

It seems impossible.

So, I created a new activity instead of a dialog and allowed the user to edit it. Please note that in the actions you can set the keyboard mode in the manifest file. I set it to show when the action opens.

Also note that testing the emulator with hard keys will not open the keyboard for SHOW_IMPLICIT or flag 0.

-2
Nov 24 '10 at 16:30
source share



All Articles