2011-11-14 26 views
7

he intentado mostrar el teclado después de inflar LinearLayout y llamo setContentView como:¿Cómo forzar al teclado a mostrar/ocultar?

InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
mgr.showSoftInput(etContent, InputMethodManager.SHOW_FORCED); 
getContent.requestFocus(); 

No funcionó. También probé esto:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 

Pero tampoco funcionó. ¿Cómo puedo forzar al teclado a mostrar/ocultar? ¿Qué hice mal?

+1

duplicado exacto de http://stackoverflow.com/questions/1109022/how-to-close-hide-the-android-soft-keyboard y http://stackoverflow.com/questions/2479504/forcing-the-soft-keyboard-open – Polynomial

Respuesta

1

this link es claro acerca de cómo ocultar el teclado virtual. para mostrar que se puede utilizar un truco - crear una EditarTexto cualquier lugar de su diseño, layout_width y layout_height = 0dip, y en onCreate hacer

yourEditText.requestFocus(); 
30

Esto debería funcionar

public class KeyBoard { 

    public static void toggle(Activity activity){ 
     InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); 
     if (imm.isActive()){ 
      imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); // hide 
     } else { 
      imm.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY); // show 
     } 
    }//end method 
}//end class 
+0

Buena respuesta todavía Vale la pena :) –

Cuestiones relacionadas