Android O自动位置建议功能(aka autofill),如何关闭

由于我们在Android O上安装了应用程序,因此在此处引入了一项新功能,根据以下图像自动建议“家庭和工作”位置。

在这里输入图像描述

这个叫什么? 有没有办法从我们的编辑文本显示它禁用它?

显然在Android-Oreo中,有一个叫做AUTOFILL的新功能

https://developer.android.com/guide/topics/text/autofill.html ,其中By default, the view uses the IMPORTANT_FOR_AUTOFILL_AUTO mode, which lets Android use its heuristics to determine if the view is important for autofill

因此,对于不打算填充的字段,只需将以下内容添加到您的视图。

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_NO); } 

更新 :找到另一种方法来禁用AUTOFILL在XML中使用android:importantForAutofill="no" https://developer.android.com/guide/topics/text/testautofill.html#trigger_autofill_in_your_app

接受的答案不是一个解决方案,它不适用于所有情况下,要禁用自动填充完全在一个特定的视图,你应该扩展它,并重写getAutofillType()方法:

 class TextInputEditTextNoAutofill : TextInputEditText { constructor(context: Context) : super(context) constructor(context: Context, attrs: AttributeSet) : super(context, attrs) constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) @RequiresApi(Build.VERSION_CODES.O) override fun getAutofillType(): Int { return View.AUTOFILL_TYPE_NONE } } 

这是Kotlin版本,但你可以明白这一点。 展示回购: https : //github.com/BukT0p/AutofillBug