6

我正在为 React Native Text Input 组件苦苦挣扎,似乎无法找到一种方法来更改光标颜色和 android 上的文本选择指示器。

官方文档只列出了一个用于选择颜色的道具(文本的高亮背景)。

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

4

2 回答 2

9

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

但是,在此之前最好停止 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.

于 2018-05-21T11:04:29.370 回答
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

资源

于 2019-02-27T19:11:31.370 回答