
参考代码:
public void setFocusEditTextAndShowSoftInput(final EditText editText){
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();//聚焦
//判断当前editText是否绘制完成,绘制完成后再进行展示软键盘
editText.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
InputMethodManager inputManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(editText, 0);//展示软键盘
}
});
}