EditText 自动填充.背景变成黄色
2020-01-08 本文已影响0人
鹅鹅鹅曲项向天歌呀
先了解一下Android 8.0的特性吧
友情链接:https://developer.android.com/guide/topics/text/autofill
这个功能,实在Android8.0以上才有的,当然了,也可以设置里面设置一下,不让自动填充.在 输入法和语言 里面.

效果图片:
一打开界面就自动提示了,下图

当选择了之后,输入框就变成浅黄色了,下图

解决方案:
用户设置了自动填充,我们用代码,也可让他不自动弹出来.把下面这行代码设置给EditText.
android:importantForAutofill="no"
或者
代码中调用 View 的 setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO)
这样可以避免用户,上来就去选择自动提示的邮箱账号,但是有的手机长按还是会出来,黏贴的功能,就还会出来自动填充的提示,有的手机不会出来,这是手机系统问题了,不管了....
方案一:
第一,主题,activity的主题.设置成透明的颜色.
<item name="android:autofilledHighlight">@android:color/transparent</item>
这样.即时自动填充,背景也不会黄色,就是透明的背景图

方案二:
第一通过在 activity 的 onCreate() 方法中加入如下代码
getWindow().getDecorView().setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
(方案二,我没用过,看人家说的)
友情链接 : https://www.jianshu.com/p/531ce99bd961
END
如有抄袭或侵权或问题,联系Q1032528317