Android 设置EditText的光标样式

如图:


步骤一

/res/drawable文件夹下创建edit_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="2dp" />

    <solid android:color="#F00" />
</shape>
步骤二

布局文件中设置EditTexttextCursorDrawable属性为edit_cursor_color

 <EditText
        android:id="@+id/et_input"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginStart="2dp"
        android:background="@drawable/edit_text_bg"
        android:inputType="text"
        android:labelFor="@id/et_input"
        android:textCursorDrawable="@drawable/edit_cursor_color"
        android:textSize="18sp"
        tools:ignore="Autofill" />
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容