作者:陈婉恩上源 | 来源:互联网 | 2023-01-22 17:48
Android O具有支持字段自动填充的功能.有什么办法可以为特定的应用程序禁用它.那是我想强制我的应用程序不使用自动填充服务.
可能吗 ?
要阻止整个活动的自动填充,请在活动的onCreate()中使用:
getWindow()
.getDecorView()
.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
有没有比这更好的方法?
1> albeee..:
目前没有直接的方法来禁用整个应用程序的自动填充,因为自动填充功能是特定于View的.
您仍然可以尝试这种方式并在任何地方调用BaseActivity .
public class BaseActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
disableAutofill();
}
@TargetApi(Build.VERSION_CODES.O)
private void disableAutofill() {
getWindow().getDecorView().setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
}
}
您也可以通过这种方式强制请求自动填充.
public void forceAutofill() {
AutofillManager afm = context.getSystemService(AutofillManager.class);
if (afm != null) {
afm.requestAutofill();
}
}
注意:目前,自动填充功能仅适用于API 26 Android Oreo 8.0
希望这可以帮助!
2> Karoly..:
我认为接受的答案是错误的:
所以我有自己的类,它扩展了android.support.v7.widget.AppCompatEditText,我所做的就是使用以下值覆盖以下方法:
@Override
public int getAutofillType() {
return AUTOFILL_TYPE_NONE;
}
没有其他解决方案有效,甚至没有android:importantForAutofill ="no".
getAutofillType()来自View类,所以它应该适用于其他所有类,如TextInputEditText!
这是目前唯一可行的解决方案,它也适用于TextInputEditText!
3> 小智..:
我也碰到了这个.事实证明,问题是由嵌套在TextInputLayout内的EditText上的提示文本引起的.
我做了一些挖掘,并在26.0.0 Beta 2发行说明中找到了这个金块.
Andorid支持发行说明2017年6月
TextInputLayout必须在onProvideAutofillStructure()上设置提示
这导致我尝试在TextInputLayout而不是嵌套的EditText上设置提示.
这解决了我的崩溃问题.例: