Android 设置EditText不显示光标
有时候需要设置EditText不显示光标,上网查了下,一般都是反射的系统方法:
if (android.os.Build.VERSION.SDK_INT <= 10) {
mEtInput.setInputType(InputType.TYPE_NULL);
} else {
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
try {
Class<EditText> cls = EditText.class;
Method setShowSoftInputOnFocus;
setShowSoftInputOnFocus = cls.getMethod("setShowSoftInputOnFocus",
boolean.class);
setShowSoftInputOnFocus.setAccessible(true);
setShowSoftInputOnFocus.invoke(mEtInput, false);
} catch (Exception e) {
e.printStackTrace();
}
}
其实,另一个标记投机简单的方法是,设置光标颜色和EditText的背景色一致也可以,用户体验是一样的。
android:textCursorDrawable="EditText的背景色"
或者设置属性:
android:cursorVisible="false"
更多相关文章
- 安装Android studio出现'tools.jar' seems to be not in Android
- Android 屏幕旋转后防止重新执行onCreate的方法。
- 【Android】‘activity supporting action_view is not set as b
- Android中完全退出程序的四种方法
- Android Activity启动和退出过程中onResume()方法的回调
- andorid跳过系统API获取以太网IP,网关,DNS,MAC的方法
- 【Android】关联source code的方法