更改 TextField 中光标的大小(Jetpack Compose)

时间:2021-06-16 10:14:14

标签: android textfield android-jetpack-compose

我想降低 TextField 中光标的“高度”。我该怎么做?

我的带有默认光标高度的 TextField 如下所示:

My TextField

1 个答案:

答案 0 :(得分:0)

res/drawable/custom_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"// cursor width
        android:height="28dp" />// cursor height should be noted that the height can not be set edittext adaptation, otherwise, the cursor height or size of the input character
    
<solid android:color="@color/azure" />// color of the cursor
    
<padding    // This parameter allows the cursor is highly inconsistent with the text size, text size I need is here 14dp
        android:bottom="7dp"
        android:top="7dp" />
</shape>

在您的编辑文本中:

android:textCursorDrawable="@drawable/custom_cursor"