原因:想实现让edittext在可编辑与不可编辑状态切换,并弹出键盘。setEnable为false后,进入页面依然会自动弹出软键盘。改为setFocusable后无效。
解决办法:setFocusable:键盘是否能获得焦点,setFocusableInTouchMode:触摸是否能获得焦点。
附关闭软键盘方法:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
}