2011-11-14 17 views
7

ho cercato di mostrare la tastiera dopo che ho gonfio LinearLayout e chiamo setContentView come:Come forzare la tastiera a mostrare/nascondere?

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

Non ha funzionato. Ho anche provato questo:

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

Ma non ha funzionato. Come posso forzare la tastiera a mostrare/nascondere? Che cosa ho fatto di sbagliato?

+1

esatto duplicato di http://stackoverflow.com/questions/1109022/how-to-close-hide-the-android-soft-keyboard e http://stackoverflow.com/questions/2479504/forcing-the-soft-keyboard-open – Polynomial

risposta

1

this link è chiaro su come nascondere la tastiera virtuale. per vederlo è possibile utilizzare un hack - creare un EditText ovunque nel layout, layout_width e layout_height = 0dip, e in onCreate fare

yourEditText.requestFocus(); 
30

Questo dovrebbe funzionare

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

Bella risposta ancora vale :) –

Problemi correlati