調用下面代碼:(第一次調用顯示,再次調用則隱藏,如此反覆),this指activity
InputMethodManager imm = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);<br /> imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);<br /> imm.showSoftInput(myview, InputMethodManager.SHOW_IMPLICIT);
單獨顯示隱藏軟鍵盤:
顯示:
InputMethodManager imm = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);<br />imm.showSoftInput(myview, 0);
隱藏:
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
程式啟動後,自動彈出軟鍵盤,可以通過設定一個時間函數來實現,不能再onCreate裡寫:
Timer timer = new Timer();</p><p>timer.schedule(new TimerTask() {<br />@Override public void run() {<br />InputMethodManager imm = (InputMethodManager)this.getSystemService(INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);</p><p>Toast.makeText(chick.this, "show", Toast.LENGTH_SHORT).show();<br />}<br />}, 1000);