如何在React Native TextInput中更改光标的宽度?

时间:2020-04-22 13:19:23

标签: react-native

我想使TextInput中闪烁的光标变细,该怎么做?正常宽度大约是3像素,我希望它有1像素。

1 个答案:

答案 0 :(得分:2)

对于android,您可以按照以下步骤操作:

步骤1:创建editext_cursor.xml并将其放置在res-> drawable目录下。

android/app/src/main/res/drawable/editext_cursor.xml

第2步:在editext_cursor.xml中粘贴以下内容:

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <size android:width="1dip" />
        <solid android:color="#010101" />
    </shape>

在这里,您可以将宽度更改为所需的任何宽度。

第3步:将该行添加到android/app/src/main/res/values/styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:textColor">#000000</item>

        <item name="android:textCursorDrawable">@drawable/editext_cursor</item> <-- add this

    </style>

</resources>

第4步:重建应用程序

相关问题