首先要在EditText的父布局中,设置两个属性.
android:focusable="true"
android:focusableInTouchMode="true"
然后我写了一个方法,调用这个方法的时候,把EditText的id传
进去就可以
public void showSoftInputFromWindow(EditText editText){
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
InputMethodManager inputManager =
(InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(editText, 0);
}