只需如下設置就可搞定:
EditText edittext = (EditText)findViewById(R.id.edittext);
edittext.setFocusable(true);
edittext.setFocusableInTouchMode(true);
edittext.requestFocus();
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
InputMethodManager inputManager =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(edittext, 0);
}
},
200);
值得注意的是,剛進去當整個view還沒有構建完畢,執行彈出軟鍵盤是沒有效果的,所以這裏加了個定時器,當進到頁面後200毫秒後纔開始彈出軟鍵盤。經測試,效果明顯。