天天看點

android自動軟鍵盤,android安卓editText自動彈出軟鍵盤(輸入鍵盤)(示例代碼)

editext擷取焦點并自動彈出輸入鍵盤,代碼如下:EditText  editText.setFocusable(true);

editText.setFocusableInTouchMode(true);

editText.requestFocus();

InputMethodManager inputManager =(InputMethodManager)editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

inputManager.showSoftInput(editText, 0);

如果是已經入某個界面就要立刻彈出輸入鍵盤,可能會由于界面未加載完成而無法彈出,需要适當延遲,比如延遲500毫秒:Timer timer = new Timer();

timer.schedule(new TimerTask()

{

public void run()

{

InputMethodManager inputManager =(InputMethodManager)editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

inputManager.showSoftInput(editText, 0);

}

},500);