【问题标题】:Yellow box appears around EditText once it has been Auto-Filled自动填充后,EditText 周围会出现黄色框
【发布时间】:2018-03-12 20:34:24
【问题描述】:

正如您将在下面的屏幕截图中看到的那样,很明显在 EditText 填写后会出现一个黄色框。注意:仅当输入的 text 为 AUTO- 时才会发生这种情况已满!!

我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <View
            android:id="@+id/view2"
            android:layout_width="match_parent"
            android:layout_height="@dimen/login_background"
            android:background="@color/colorPrimary" />

        <View
            android:id="@+id/view"
            android:layout_width="@dimen/login_container_width"
            android:layout_height="@dimen/login_container_height"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/login_container_margin_top"
            android:background="@drawable/login_container"
            android:elevation="8dp">

        </View>

        <Button
            android:id="@+id/button"
            android:layout_width="250dp"
            android:layout_height="50dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="55dp"
            android:background="@drawable/login_button"
            android:elevation="10dp"
            android:stateListAnimator="@null"
            android:text="LOGIN"
            android:textColor="@color/white"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/editText"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:elevation="10dp"
            android:ems="10"
            android:hint="Email address"
            android:inputType="textEmailAddress"
            android:textColor="@color/colorPrimary"
            android:layout_below="@+id/view2"
            android:layout_centerHorizontal="true"
            android:stateListAnimator="@null" />

        <EditText
            android:id="@+id/editText2"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="23dp"
            android:ems="10"
            android:inputType="textPassword"
            android:elevation="10dp"
            android:hint="Password"
            android:textColor="@color/colorPrimary"
            android:layout_below="@+id/editText"
            android:layout_alignStart="@+id/editText"
            android:stateListAnimator="@null" />

    </RelativeLayout>

</LinearLayout>

【问题讨论】:

  • 您在使用 appcompat 吗?如果没有,请切换到 appcompat。两个不相关的问题 - 你为什么使用ems?这不是 CSS,您应该使用 textSizesp 中的单位。你真的知道stateListAnimator 属性的作用吗?我以前从来没有用过它,你可能不需要它。
  • 我确实在使用 AppCompat 库。至于其他问题,我已经做了必要的改变。 stateListAnimator 是我的错,我在复制/粘贴后不小心把它留在了里面,但是问题仍然存在。
  • 是的,这些不相关。好的,那么它将 appcompat 主题化您的编辑文本。你可以尝试手动更改背景吗?对于初学者,将其设置为纯灰色,仅供初学者使用
  • 我使用了 android:background="#808080" 它只是覆盖了颜色并将其设置为黄色。但是,它混合了灰色和黄色,所以变成了一种吝啬的灰色
  • 哇!没想到。也许.. 深入应用兼容性以查看背景可绘制对象将其设置为黄色的状态是什么?

标签: android android-edittext autofill


【解决方案1】:

您可以自定义该自动填充的背景。 创建新样式文件 res/values-v26/styles.xml, 将应用程序主题的副本添加到该文件中,并添加一行

<item name="android:autofilledHighlight">@android:color/transparent</item>

在这种情况下它将是透明的,这就是我想要实现的,但你可以使用任何你喜欢的颜色。 https://developer.android.com/guide/topics/text/autofill

【讨论】:

  • 谢谢。您必须确保将其放在您的应用程序主题下。将此添加到任何其他主题都行不通
  • 正确。像魅力一样工作。如果使用 Oreo 以上版本,只需添加 tools:ignore="NewApi" 行。
  • 有没有办法避免重复样式规范的其余部分(在 values 和 values-v26 中)?
猜你喜欢
  • 1970-01-01
  • 2016-08-31
  • 2014-12-13
  • 2016-11-21
  • 1970-01-01
  • 1970-01-01
  • 2017-06-11
  • 2011-02-24
  • 2019-07-09
相关资源
最近更新 更多