这次要专门说说光标的问题了。我们对EditText很熟悉,作为输入控件,EditText是我们很常用的一个控件。我们对EditText有很多种操作,但是,你有没有想过对光标进行相关的操作?这个操作可以说比较冷门,但是对于产品经理可是不算冷门,他们可能早就看着那个光标不爽了。为了不然众多产品经理鄙视我们的技术,在这里我贴出有关光标的修改方法。
首先是光标的显隐
布局中我们使用cursorVisible属性来改变光标的显示隐藏,在代码中我们也可以使用setCursorVisible方法设置光标的显示隐藏。
其次是光标的宽度和颜色
我们先定义一个drawable:shape_et_cursor_color.xml,代码如下
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="@dimen/x2"/>
<solid android:color="@color/orange_custom"/>
</shape>
其次就是在布局中对应的EditText进行引用
<EditText
android:id="@+id/et_content"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@id/tv_des"
android:textColorHint="@color/gray_edit_text_hint"
android:maxLines="1"
android:background="@null"
android:textCursorDrawable="@drawable/shape_et_cursor_color"/> //这句是重点
这样就实现了对光标宽度和颜色的修改。