您的位置:首页 > 其它

禁止Edittext弹出软键盘并且使光标正常显示

2016-03-04 12:20 281 查看
原文地址http://blog.csdn.net/u011494050/article/details/38457315

直接主类里边添加代码后调用就可以了,既可以禁用键盘,又可以保留光标,完美

</pre><pre code_snippet_id="1596968" snippet_file_name="blog_20160304_4_5816719" name="code" class="java">/**
* 禁止Edittext弹出软件盘,光标依然正常显示。
*/
public void disableShowSoftInput()
{
if (android.os.Build.VERSION.SDK_INT <= 10)
{
editText.setInputType(InputType.TYPE_NULL);
}
else {
Class<EditText> cls = EditText.class;
Method method;
try {
method = cls.getMethod("setShowSoftInputOnFocus",boolean.class);
method.setAccessible(true);
method.invoke(editText, false);
}catch (Exception e) {
// TODO: handle exception
}

try {
method = cls.getMethod("setSoftInputShownOnFocus",boolean.class);
method.setAccessible(true);
method.invoke(editText, false);
}catch (Exception e) {
// TODO: handle exception
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: