更改反应本机上文本输入突出显示(自动完成)的背景颜色

Hen*_*sma 6 autocomplete highlight background-color react-native

当 TextInput 从 React Native 上已经存在的 autoCompleteType 中突出显示时,如何更改 TextInput 的背景颜色?就像这张图片上的那样

这是图像

Kev*_*get 10

要自定义此自动填充背景颜色,您必须在 android 级别进行设置

  1. 使用您选择的名称创建一个 xml 文件,例如android/app/src/main/res/drawable中的autofill_highlight.xml

  2. 将此代码放入其中:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="@android:color/transparent" />
    </shape>
    
    Run Code Online (Sandbox Code Playgroud)

    在这里,颜色集是透明的(“@android:color/transparent”),将其替换为您的颜色。

  3. android/app/src/main/res/values/styles.xml中,将此行添加到您的应用程序主题中(如果您不像我的示例中那样将其称为 autofill_highlight ,请确保提供您自己的文件名

    <resources>
         <!-- Base application theme. -->
         <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    
             <!-- ... your other theme customization ...  -->
    
             <!-- ADD THE FOLLOWING LINE -->
             <item name="android:autofilledHighlight">@drawable/autofill_highlight</item>
    
        </style>
    </resources>
    
    Run Code Online (Sandbox Code Playgroud)
  4. 重建您的应用程序:)