Android 修改EditView输入框的光标颜色

时间:2022-07-25
本文章向大家介绍Android 修改EditView输入框的光标颜色,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

前言

都知道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" />
</shape>

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

			<EditText
                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"/>

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