606
技術社區[雲棲]
android 軟鍵盤 InputMethodManager
原文:https://blog.csdn.net/pilou5400/article/details/5954905
調用下麵代碼:(第一次調用顯示,再次調用則隱藏,如此反複),this指activity
InputMethodManager imm = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); imm.showSoftInput(myview, InputMethodManager.SHOW_IMPLICIT);
單獨顯示隱藏軟鍵盤:
顯示:
InputMethodManager imm = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(myview, 0);
隱藏:
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
程序啟動後,自動彈出軟鍵盤,可以通過設置一個時間函數來實現,不能再onCreate裏寫:
Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { InputMethodManager imm = (InputMethodManager)this.getSystemService(INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); Toast.makeText(chick.this, "show", Toast.LENGTH_SHORT).show(); } }, 1000);
最後更新:2017-04-02 06:52:05