I read a couple of posts here, and also tried a google search. But I still have this problem:
I created a subclass user dialog. It contains an EditText and a button ("OK"). I want the keyboard to appear automatically after the dialog box appears.
I succeeded by putting this:
imm = (InputMethodManager) EditDialog.this.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS);
in my onCreate () custom dialog and
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
in my dismissal ().
This opens the keyboard after the dialog box appears, and also closes the keyboard when I click OK.
However, if the Soft Keyboard is open, and I press the HOME button of my phone / emulator, the keyboard will remain open, as I understand it, I force it to open SHOW_FORCED. So I tried to hide the keyboard (using toggleSoftInput () from InputMethodManager) if it is open in the parent action of the onPause () dialog. this only seems possible with a workaround as shown HERE .
TL DR . I want the soft keyboard to appear when my dialog is called using EditText and a button (focus on EditText). I got this job, but it involves writing many hacks to close it properly.
Change I based my code on IT
source share