【问题标题】:Change the background color of textInput highlight (autocomplete) on react-native在 react-native 上更改 textInput 突出显示(自动完成)的背景颜色
【发布时间】:2020-04-19 06:19:39
【问题描述】:

当 TextInput 从 react native 中已经存在的 autoCompleteType 中获得高亮显示时,如何更改它的背景颜色? 喜欢这张图片

【问题讨论】:

  • 还没有解决办法?

标签: react-native autocomplete background-color highlight


【解决方案1】:

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

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

  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>
    

    这里,颜色集是透明的(“@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>
    
  4. 重建您的应用程序:)

【讨论】:

    猜你喜欢
    • 2019-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    • 2013-03-21
    • 2013-01-09
    • 2022-01-15
    相关资源
    最近更新 更多