Android softkeyboard showSoftInput vs toggleSoftInput

showSoftInput() no muestra el teclado para mí, pero toggleSoftInput() hace. Vi otro post que decía para desactivar el teclado duro cuando se utiliza el emulador, pero no estoy usando un emulador. Estoy cargando mi APK en un dispositivo real sin teclado duro. ¿No deberían funcionar ambos métodos? ¿Por qué no funciona showSoftInput() ? Me gustaría asociar explícitamente el teclado con un campo de texto específico.

No funciona:

 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); editText.setText("textchange"); //i see the text field update imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED); 

Trabajos:

 InputMethodManager imm = (InputMethodManager) getDelegate().getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0); 

Parece que el teclado se muestra inicialmente, pero está oculto por otra cosa, porque lo siguiente funciona (pero en realidad es un trabajo sucio):

 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); editText.postDelayed(new Runnable() { @Override public void run() { editText.requestFocus(); imm.showSoftInput(editText, 0); } }, 100); 

Y al mirar logcat sospecho que la causa detrás de este mensaje oculta el teclado inicialmente mostrado:

Ocultar el cuadro de diálogo del Portapapeles en la entrada de inicio: terminado por alguien más …!

Mostrar Teclado + enfoque y también si desea Ocultar el teclado

 @Override public void onResume () { super.onResume(); inputSearch.setFocusableInTouchMode(true); inputSearch.requestFocus(); // Show Keyboard InputMethodManager imm = (InputMethodManager) getSherlockActivity().getSystemService( Context.INPUT_METHOD_SERVICE); imm.showSoftInput(inputSearch, InputMethodManager.SHOW_IMPLICIT); } 

PS inputSearch = (EditText) getSherlockActivity (). FindViewById (R.id.inputSearch);

  // Hide Keyboard InputMethodManager imm = (InputMethodManager) getSherlockActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(inputSearch.getWindowToken(), 0); 

La respuesta precisa a esta pregunta ¿por qué doesSoftInput no funciona y toggleSoftInput hace?

Es que la vista a la que está intentando mostrar el teclado no tiene el foco. Así que para resolver este problema y para usar el método showSoftInput tendrás que llamar a los siguientes métodos en tu vista:

  setFocusable(true); setFocusableInTouchMode(true); 

Al llamar a los métodos anteriores se asegurará de que al hacer clic en la vista se conserva y se captura el foco.

ShowSoftInput () no funciona cuando el dispositivo tiene un teclado duro (deslizable)

Android show softkeyboard con showSoftInput no funciona?

Prueba esto:

 public void showTheKeyboard(Context context, EditText editText){ InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); } 

Si esto no funciona, lee el tutorial desde aquí

 public void hideKeyboard() { myTextView.setFocusable(true); myTextView.setFocusableInTouchMode(true); imm.hideSoftInputFromWindow(myTextView.getWindowToken(), 0); } 

TRABAJOS

 public void hideKeyboard() { imm.hideSoftInputFromWindow(myTextView.getWindowToken(), 0); } 

NO FUNCIONA

Imm se trata antes como estoy usando un fragmento así:

Declare imm en el fragmento

 private InputMethodManager imm; 

A continuación, en el fragmento añadir:

 @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); } 

Él dice después de 3 a 4 horas de investigación y fracasos!

Gracias user_CC! Todos los derechos reservados

Phil

FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.