Cuando se utiliza AlertDialog.Builder con EditText, el Soft Keyboard no aparece
Estoy utilizando AlertDialog.Builder para crear un cuadro de entrada, con EditText como el método de entrada.
Desafortunadamente, el Soft Keyboard no aparece, aunque el EditText está enfocado, a menos que explícitamente lo toque de nuevo.
- Cómo utilizar el teclado suave android en SurfaceView
- Deshabilitar la vista de edición de pantalla completa para la entrada de teclado suave en el paisaje, desde la perspectiva del usuario?
- ¿Cómo obtener sugerencias de auto-corrección de teclado suave?
- El teclado de Android no se abre cuando se usan consultas de medios
- InputConnection.commitText (texto CharSequence, int newCursorPosition) sólo puede confirmar caracteres y números en inglés?
¿Hay una manera de forzarla a estallar?
He intentado lo siguiente, después de (AlertDialog.Builder) .show (); Pero en vano.
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); mgr.showSoftInput(input, InputMethodManager.SHOW_FORCED);
¿Alguien puede ayudar?
¡¡Gracias!!
- Cómo deshabilitar "métodos de entrada" en SoftKeyBoard?
- Android: Cargando JavaScript con WebView.loadUrl pero manteniendo el teclado virtual
- ¿Deshabilitar la vista de edición de pantalla completa para la entrada de teclado suave en paisaje?
- Ocultar Teclado suave en la tecla de retorno pulsa
- Mostrar teclas de emoji incorporadas para inputmethod
He hecho tal cosa
AlertDialog.Builder b = new AlertDialog.Builder(this);//.... AlertDialog dialog = b.create(); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); dialog.show();
He conseguido solucionarlo así:
Dialog = builder.create(); Dialog.show(); Dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); Dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
Me enteré de que el mismo código funciona correctamente en Tablet, el teclado aparece, pero en el teléfono no, por lo que la investigación, parece apuntar a la opción "ajustar".
Estoy usando esto, se siente mucho más limpio.
AlertDialog d = builder.create(); d.getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); d.show();
Cuando llama a showDialog para mostrar un Diálogo creado usando AlertDialog en onCreateDialog
Usted debe poner el código aquí
@Override protected void onPrepareDialog (int id, Dialog dialog, Bundle args) { TextView editText=(TextView) dialog.findViewById(R....); 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); } } }); }
Una solución mucho mejor se da aquí .
dialog.getWindow().clearFlags( WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
No hay solución. EditText
comporta como se esperaba.
Window window = dialog.getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Esto ya fue contestado aquí . El uso de OnFocusChangeListener funcionó para mí.
Prueba esto, está funcionando para mí
Si desea mostrar el teclado virtual:
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(input.getWindowToken(), 0);
Y si quieres ocultarlo:
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
final AlertDialog.Builder alert = new AlertDialog.Builder(context); final AlertDialog dialog = alert.show(); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);