EditText自定义下划线

EditText自带的下划线显示太丑了,往往需要我们自定义或者不显示下划线,当我们设置为background属性为@null的时候是不显示下划线的。

  • 自定义下划线我们需要在drawable文件夹先新建一个shape_edit_bottom_line.xml文件
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:top="-2dp"
        android:right="-2dp"
        android:left="-2dp">
        <shape>
            <solid android:color="#F6F6F6"/>
            <stroke
                android:width="1dp"
                android:color="#EFEFEF"/>
        </shape>
    </item>
</layer-list>
  • 自定义光标,新建一个shape_edit_cursor.xml文件
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
           android:shape="rectangle">
        <size android:width="2dp"/>
        <solid android:color="#6A6A6A"/>
    </shape>
  • 我们在布局文件中这样使用

 <EditText
            android:id="@+id/et"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/shape_edit_bottom_line"
            android:hint="请输入内容"
            android:inputType="textPassword"
            android:textColor="#333333"
            android:textColorHint="#a3a3a3"
            android:textCursorDrawable="@drawable/shape_edit_cursor"
            android:textSize="16sp"/>

以上就是EditText自定义光标和下划线

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值