前言
之前项目中碰到过,好久不用又忘了,今天在这里做个笔记方便日后查询吧。
内容
先看下我的EditText标签
<EditText
android:id="@+id/et_org"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@android:color/white"
android:hint="请输入内容"
android:maxLength="20"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:singleLine="true"
android:textColor="#000000"
android:textSize="16sp"
>
</EditText>
也没有添加比较特殊的属性,但光标就是无缘无故的消失了,在这里猜测可能是安卓的一个bug吧,有哪位大神知道可以留言指点
这里直接说下解决办法吧,此处可以直接通过添加
android:textCursorDrawable="@null"
加上这句光标就出来了,不过在有的机型上可能会变成空心,也就是只有两条竖线的空心。
这样的话我们可以通过自定义一个shape来达到理想效果
1、在资源文件drawable下新建一个光标控制cursor_color.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size android:width="1dp" />
<solid android:color="#000000" />
</shape>
2、设置EditText:EditText:android:textCursorDrawable=”@drawable/cursor_color”
这样不仅显示正常,还可以改变光标颜色!