When Using Alertdialog.Builder with Edittext, The Soft Keyboard Doesn't Pop

AlertDialog EditText doesn't show a soft keyboard

#. Add focus change listener to your TextInputEditText and in onFocusChange() show keyboard using .toggleSoftInput(InputMethodManager.SHOW_FORCED, 0).

Required to open keyboard:

final TextInputEditText input = new TextInputEditText(this);

// Keyboard
final InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);

// Auto show keyboard
input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean isFocused) {

if (isFocused) {
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
}
});

#. Use below code to hide keyboard when your dialog's button pressed.

Required to hide keyboard:

// Hide keyboard
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);

Hope this will help~

Soft KeyBoard not pop up in EditText of AlertDialog

Try out this way:

 public class FirstStartDialog extends Dialog {
Context context;
final AlertDialog.Builder alert;
public FirstStartDialog(Context p_context) {
super(p_context);
context = p_context;
alert = new AlertDialog.Builder(context);
}
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
LayoutInflater inflater = getLayoutInflater();
View container = inflater.inflate(R.layout.new_account_dialog, null);
final EditText editText_registration_username = (EditText)container.findViewById(R.id.etxt_User_Name);
editText_registration_username
.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) { ((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(editText_registration_username,
InputMethodManager.SHOW_FORCED);
}
}
});
setContentView(container);
} }

Implement your dialog as above you will get the keyboard open.

Android: EditText in Dialog doesn't pull up soft keyboard

OK, so after reading a lot, I have figured out why this is a problem, and I do not need to use any workarounds.

The problem seems to be (at least in my case), that since the place where you enter text is hidden initially (or nested or something), AlertDialog is automatically setting the flag WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM (or some combination of that and WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) so that things don't trigger a soft input to show up.

The way that I've found to fix this is to add the following line after the dialog has been created:

dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

Once this is done, the EditText acts like a normal EditText, no kludges or workarounds necessary.

Default Focus and Keyboard to EditText in Android AlertDialog

Use the following code. It worked for me.

    editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
editText.post(new Runnable() {
@Override
public void run() {
InputMethodManager inputMethodManager= (InputMethodManager) YourActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
});
}
});
editText.requestFocus();

How to display soft keyboard after AlertDialog show

alertDialog.window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM)

EditText backspace doesn't work using soft keyboard

If you have setOnKeyListener it should return false for events to get triggered.

Android: show soft keyboard automatically when focus is on an EditText

You can create a focus listener on the EditText on the AlertDialog, then get the AlertDialog's Window. From there you can make the soft keyboard show by calling setSoftInputMode.

final AlertDialog dialog = ...;

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});

Displaying soft keyboard whenever AlertDialog.Builder object is opened

With the encouragement of Mur Votema (see his answer above) I have answered my question by building a custom dialog based on the Dialog class. Unlike an alert based on AlertDialog.Builder such a custom dialog does accept the getWindow().setSoftInputMode(...) command and therefore allows the soft keyboard to be displayed automatically.

For guidance on building a custom dialog I found this web page and this especially helpful.



Related Topics



Leave a reply



Submit