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 Android PtrFrameLayout实现下拉刷新与上拉加载更多
Android PtrFrameLayout实现下拉刷新与上拉加载更多
2
url参数和map之间的转换
url参数和map之间的转换
3
Python数组遍历
Python数组遍历
4
ARouter 接入踩坑记录
ARouter 接入踩坑记录
5
SpringBoot Apollo客户端监听配置变化、动态刷新
SpringBoot Apollo客户端监听配置变化、动态刷新
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。