转载请标明 :http://77blogs.com/?p=555
在Editext的布局属性上加上
android:textCursorDrawable=”@drawable/cursor_shape”
cursor_shape如下:
1 2 3 4 5 6 7 8 9 10 11 |
<?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
从下面的源码可以大概看出原因:
1 2 3 4 5 6 7 8 9 10 |
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); } |