前言

都知道Android原生的控件颜色比较辣眼睛,所以实际开发中都会有改动,所以我们今天来改一下输入框光标的默认颜色。
在drawble下面创建一个名为cursor_style.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="#4A90E2"

然后再布局文件中使用即可

android:id="@+id/ed_pwd"
android:textCursorDrawable="@drawable/cursor_style"
android:textColor="#000"
android:textSize="@dimen/sp_24"
android:paddingLeft="@dimen/dp_15"
android:layout_width="wrap_content"
android:layout_height="@dimen/dp_65"/>

然后就可以看到蓝色的光标了。

默认的下划线会根据你的Android版本来设置,之前都是比较的辣眼睛,都是常规使用中,要么是通过设置background="null"的方式不要背景,然后通过一个View来设置下划线,要么是通过设置样式来修改系统自带的下划线。

下面通过样式来设置一下,在styles.xml中增加一个样式:

"MyEditText" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">@color/green_2ead4d</item>
<item name="colorControlActivated">@color/green_2ead4d</item>
</style>

green_2ead4d的色值是:

<color name="green_2ead4d">#2ead4d</color>

然后在布局中设置这个样式的值。

Android 修改EditView输入框的光标颜色、下划线颜色_下划线


这样就可以修改下划线的颜色了,去试试吧。