软件编程
位置:首页>> 软件编程>> Android编程>> Android开发中自定义 editText下划线

Android开发中自定义 editText下划线

作者:xwg11  发布时间:2023-03-30 13:40:35 

标签:editText,下划线

看了下网上代码:

我想要的效果如下图

Android开发中自定义 editText下划线

下划线和文字有15dp的间距   eeeeee的颜色

上代码,

<"1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
           android:bottom="0dp"
           android:left="-1dp"
           android:right="-1dp"
           android:top="-1dp">
       <shape>
           <solid android:color="@android:color/transparent" />
           <stroke      android:color="@color/color_eeeeee"
                        android:width="1dp" />
           <padding android:bottom="15dp" />

</shape>
   </item>

</layer-list>

那么 就会变成4边都有边框包裹,这里设置-1dp 是抹去不想显示的边框,因为只需要下划线  ,所以上下左全部设置成-1dp,

shape中的 stroke  中  2个属性 ,一个是color  表示边框的颜色,width表示边框的宽度。我这里设置1DP

需求是文字与下划线间隔15DP  ,那么就在<padding 中设置bottom 为15dp。

再写个selector  就可以用了

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_focused="false" android:drawable="@drawable/et_underline_selected"/>
   <item android:state_focused="true" android:drawable="@drawable/et_underline_selected"/>
</selector>

然后把这个样式设置成edittext的默认样式,以后就不用每次都调用这个了

具体操作如下

现在androidManifest中找到你系统的样式

Android开发中自定义 editText下划线

Android开发中自定义 editText下划线

来源:https://blog.51cto.com/u_13045684/6106730

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com