当前位置: 移动技术网 > IT编程>移动开发>Android > 设置Editext的光标宽高与颜色

设置Editext的光标宽高与颜色

2018年09月13日  | 移动技术网IT编程  | 我要评论

黄圣依乳晕,修真神偷2,acmetea官网

在editext的布局属性上加上

android:textcursordrawable="@drawable/cursor_shape"

 

cursor_shape如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <size
        android:width="1dp" />
    <solid android:color="@color/comics_theme_color" />

    <padding
        android:top="-2dp"
        android:bottom="-2dp"/>
</shape>

事实证明:设置android:height无效,应该用padding的方法。

top设置为-2dp :让光标顶部下移2dp

bottom设置为-2dp:让光标底部上移2dp

这样子光标的高度就变小了4dp

 

从下面的源码可以大概看出原因:

private void updatecursorposition(int cursorindex, int top, int bottom, float horizontal) {
    ...
 
    mcursordrawable[cursorindex].getpadding(mtemprect);
 
    ...
 
    mcursordrawable[cursorindex].setbounds(left, top - mtemprect.top, left + width,
            bottom + mtemprect.bottom);
}

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网