Android下EditText使用android:lineSpacingExtra設(shè)置了行距,顯示時(shí)光標(biāo)的高度也會(huì)增加。

Paste_Image.png
解決方法:自定義cursor光標(biāo)的背景,設(shè)置padding bottom的值為負(fù)值,就可以抵消行間距的影響(android 14)以上。
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="14sp"
android:lineSpacingExtra="10dp"
android:textCursorDrawable="@drawable/color_cursor" />
color_cursor.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="2dp"/>
<padding android:bottom="-10sp"></padding>
<solid android:color="@color/contractions"/>
</shape>