EditText使用小结

一.EditText 光标设置

android:cursorVisible="true"//显示


android:cursorVisible="false"//隐藏


二.设置光标颜色

android:textCursorDrawable,这个属性是用来控制光标颜色的


android:textCursorDrawable="@null","@null"作用是让光标颜色和text color一样


但是我直接用textCursorDrawable加上颜色值时,光标并不显示颜色,后来写了一个drawable文件来设置EditText光标的颜色和粗细,亲测有效.


<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <size android:width="0.5dp" />
    <solid android:color="@color/red"  />

</shape>

在xml布局中引用:


android:textCursorDrawable="@drawable/color_cursor"


三.EditText默认不显示光标,不可编辑,点击它,进入编辑状态,光标显示


JAVA代码中设置EditText不可编辑,光标不可见:


et.setCursorVisible(false);


设置EditText可编辑,光标可见:


et.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
        et.setCursorVisible(true);
   }
});

你可能感兴趣的:(android,EditText,光标颜色,点击可编辑,设置光标)