屏蔽系统键盘

2018-01-30 10:53:40来源:oschina作者:花未眠001人点击

分享
第七城市th7cn

备注:


4.0的函数名是"setSoftInputShownOnFocus",4.2后又改成了"setShowSoftInputOnFocus"


------------------------------------------------------------------------------------------ // 隐藏系统键盘 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);int currentVersion = android.os.Build.VERSION.SDK_INT; String methodName = null; if(currentVersion >= 16){// 4.2methodName = "setShowSoftInputOnFocus"; } else if(currentVersion >= 14){// 4.0methodName = "setSoftInputShownOnFocus"; }if(methodName == null){//4.0以下ed.setInputType(InputType.TYPE_NULL);} else{Class cls = EditText.class; Method setShowSoftInputOnFocus; try { setShowSoftInputOnFocus = cls.getMethod(methodName, boolean.class); setShowSoftInputOnFocus.setAccessible(true);setShowSoftInputOnFocus.invoke(ed, false);} catch (Exception e) { ed.setInputType(InputType.TYPE_NULL); e.printStackTrace();} }

第七城市th7cn

微信扫一扫

第七城市微信公众平台