Reputation: 3164
I need an EditText
as custom title view in an AlertDialog
, built by an AlertDialog.Builder
. Setting and displaying this EditText pans out, as does pasting text to it (via long click on) including EditorActionListener callbacks being called.
But there is no soft input visible, thus adding text to it is quite inconvenient. I already tried calling InputMethodManager.showSoftInput()
, but nothing happens, neither before and after creating/showing the dialog, nor in OnClickListener
, nor in OnFocusChangeListener
nor in a extra Runnable
.
What makes me stumble is that i have many other AlertDialogs with lots of EditText
s in them working as desired. Is there a conceptual difference between the custom title view and the content view?
Upvotes: 2
Views: 659
Reputation: 3164
Solution:
The AlertDialog's AlertController sets flags to block the soft input. Therefore, do this:
AlertDialog.Builder builder = .... // initialize, set up
AlertDialog d = builder.show();
d.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
d.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Now soft input shows, resizes the dialog and everything works. (Thanks to GrepCode by the way...).
Upvotes: 4