EditText光标不显示问题

前言

之前项目中碰到过,好久不用又忘了,今天在这里做个笔记方便日后查询吧。

内容

先看下我的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”
这样不仅显示正常,还可以改变光标颜色!

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值