React-native android Styling textInput [英] React-native android Styling textInput
问题描述
有没有办法在react-native android中设置textInput的样式?
喜欢在选择时更改underlineColor和光标颜色吗?
Is there a way to style the textInput in react-native android? Like change the underlineColor when selected and the cursor color?
推荐答案
从React Native版本0.21开始,仍然有无法通过视图道具设置光标颜色的样式。我已经通过向我的应用主题添加自定义样式来成功设置了光标颜色的样式。
As of React Native version 0.21, there is still no way to style the cursor color via view props. I have successfully styled the cursor color by adding a custom style to my app theme.
您需要将此代码放在 styles.xml中
文件,位于您的React项目的android文件夹中,位于 android / app / src / main / res / values / styles.xml
。
You will want to place this code in the styles.xml
file, which is located in the android folder of your React project, at android/app/src/main/res/values/styles.xml
.
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- typical material style colors -->
<item name="colorPrimary">@color/kio_turquoise</item>
<item name="colorPrimaryDark">@color/kio_hot_pink</item>
<!-- sets cursor color -->
<item name="colorControlActivated">@android:color/black</item>
</style>
</resources>
请注意,此样式为全局样式,并将为所有Android设置光标颜色 TextInput
React Native应用程序中的视图。
Note that this style is global, and will set the cursor color for all Android TextInput
views in your React Native app.
这篇关于React-native android Styling textInput的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!