Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make the Soft Keyboard appear once I show a Dialog with an EditText?
    text
    copied!<p>I read a couple of the posts here and also tried googling. But I still have this problem:<br> I have made a subclassed custom Dialog. It contains an EditText and a Button ("OK"). I want to have the keyboard show automatically once the dialog pops up.</p> <p>I succeeded doing so by putting this:</p> <pre><code>imm = (InputMethodManager) EditDialog.this.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS); </code></pre> <p>in my <em>onCreate()</em> of the custom dialog and</p> <pre><code>imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); </code></pre> <p>in my <em>dismiss()</em>.</p> <p>This opens the keyboards once the dialog pops up and also closes the keyboard once I press the "OK" button.</p> <p>However, if the Soft Keyboard is open and I press the HOME Button of my phone/the emulator, they keyboard will stay open, since - I figured - I force it open with SHOW_FORCED. I thus tried to hide (using toggleSoftInput() from InputMethodManager) the keyboard if it is open in the dialog's parent activity onPause() method. this seems only to be possible using a workaround, as seen <a href="https://stackoverflow.com/questions/2150078/android-is-software-keyboard-shown">HERE</a>.</p> <p><strong>TL;DR</strong>: I want the Soft Keyboard to be shown when my Dialog with an EditText and a Button pops up (focus on EditText). I got that working but it involved writing many hacks to <em>close</em> it properly.</p> <p><strong>Edit</strong>: I based my code on <a href="http://www.mail-archive.com/android-developers@googlegroups.com/msg58137.html" rel="nofollow noreferrer">THIS</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload