反应原生文本输入Android光标/插入符号和文本光标颜色

问题描述 投票:3回答:2

我正在努力使用React Native Text Input组件,似乎无法找到更改光标颜色和android上文本选择指示器的方法。

官方文档仅列出了选择颜色的支柱(文本的突出显示背景)。

有没有办法在不改变全局的情况下做到这一点?如果在全球范围内更改它是正确的方法,那么最好的方法是什么?在styles.xml中更改它?当我尝试更改它时,React-Native崩溃。

android react-native react-native-android textinput
2个回答
7
投票

我们可以在位于android/app/src/main/res/values/styles.xml的styles.xml文件中为android更改它

但是,在此之前最好停止NodeJS服务器,然后进行以下更改

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

        <!-- Customize your theme here. -->
        <item name="colorControlActivated">@android:color/white</item>
    </style>

</resources>

您还可以通过使用以下代码在同一目录中添加colors.xml文件来添加自定义十六进制颜色代码。

<resources>
    <color name="primaryRed">#EB1E27</color>
</resources>

然后在你的styles.xml文件中,您可以使用@color/primaryRed引用该颜色。看起来像这样:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

        <!-- Customize your theme here. -->
        <item name="colorControlActivated">@color/primaryRed</item>
    </style>
</resources>

完成后,建议使用Android studio重新构建项目,如果构建成功,则可以运行react-native run-android


0
投票

戈德温的回答帮助了我,但事后我不得不这样做

cd android
./gradlew clean
cd ..
react-native run-android

因为构建会抛出这个错误Failed to capture snapshot of output files for task ':app:processDebugResources' property 'sourceOutputDir' during up-to-date check

Source

© www.soinside.com 2019 - 2024. All rights reserved.