![【android】禁止Edittext弹出软键盘而且使光标正常显示 【android】禁止Edittext弹出软键盘而且使光标正常显示](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
/**
* 禁止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
}
}
}