Android设置EditText光标位置、粗细颜色

光标位置

  • 如果设置的是起始位置,只需要在xml文件中加上
android:gravity="right"

即可让光标默认在最右侧闪烁。

  • 如果设置指定的位置,需要在代码中
EditText et = (EditText) findViewById(R.id.editText);
et.setSelection(et.getText().toString().length());

指定即可。length是在文字最后端闪烁。

粗细颜色

设置光标颜色和粗细。需要在drawable目录下新建的shape.xml文件中

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <size android:width="1dp" />
    <solid android:color="#008000" />
</shape>

在EditText设置

android:textCursorDrawable="@drawable/shape"

如果设置

android:textCursorDrawable="@null"

则默认跟textColor颜色一样

上一篇 Android Activity设置全屏显示
下一篇 Android ScrollView中软键盘顶上整个布局
目录
文章列表
1 OpenLDAP + phpLDAPadmin
OpenLDAP + phpLDAPadmin
2
Kibana新建index pattern卡住的解决
Kibana新建index pattern卡住的解决
3
Flutter Widget之Stepper
Flutter Widget之Stepper
4
Jenkins构建Android apk执行Shell配置
Jenkins构建Android apk执行Shell配置
5
Java后台管理站框架
Java后台管理站框架
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。