/**
* 禁止Edittext弹出软件盘,光标依然正常显示。
*/
public static void disableShowSoftInput(EditText editText) {
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
}
}
}
参考:
本文提供了一种在Android应用中禁用EditText控件弹出软键盘的方法,同时确保光标的正常显示。通过调整输入类型或使用反射调用方法,可以有效控制软键盘的显示行为。
2851

被折叠的 条评论
为什么被折叠?



