有时候需要设置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"

更多相关文章

  1. 安装Android studio出现'tools.jar' seems to be not in Android
  2. Android 屏幕旋转后防止重新执行onCreate的方法。
  3. 【Android】‘activity supporting action_view is not set as b
  4. Android中完全退出程序的四种方法
  5. Android Activity启动和退出过程中onResume()方法的回调
  6. andorid跳过系统API获取以太网IP,网关,DNS,MAC的方法
  7. 【Android】关联source code的方法

随机推荐

  1. 如何一个android工程作为另外一个android
  2. 关于FrameLayout布局的位置问题
  3. 安卓样式之shape(形状)
  4. 【Android(安卓)开发】: Android(安卓)消
  5. Android:使用命令行工具adb、mksdcard等
  6. Android(安卓)SELinux 概览(转自官网)
  7. 十六周总结报告
  8. Android之监听手机软键盘弹起与关闭
  9. Android布局优化(二)优雅获取界面布局耗时
  10. Android占领2010的六大理由!