jgm*_*jgm 34 android autofill textview android-8.0-oreo android-autofill-manager
Android O具有支持字段自动填充的功能.有什么办法可以为特定的应用程序禁用它.那是我想强制我的应用程序不使用自动填充服务.
可能吗 ?
要阻止整个活动的自动填充,请在活动的onCreate()中使用:
getWindow()
.getDecorView()
.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
Run Code Online (Sandbox Code Playgroud)
有没有比这更好的方法?
alb*_*eee 23
目前没有直接的方法来禁用整个应用程序的自动填充,因为自动填充功能是特定于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);
}
}
Run Code Online (Sandbox Code Playgroud)
您也可以通过这种方式强制请求自动填充.
public void forceAutofill() {
AutofillManager afm = context.getSystemService(AutofillManager.class);
if (afm != null) {
afm.requestAutofill();
}
}
Run Code Online (Sandbox Code Playgroud)
注意:目前,自动填充功能仅适用于API 26 Android Oreo 8.0
希望这可以帮助!
Kar*_*oly 18
我认为接受的答案是错误的:
所以我有自己的类,它扩展了android.support.v7.widget.AppCompatEditText,我所做的就是使用以下值覆盖以下方法:
@Override
public int getAutofillType() {
return AUTOFILL_TYPE_NONE;
}
Run Code Online (Sandbox Code Playgroud)
没有其他解决方案有效,甚至没有android:importantForAutofill ="no".
getAutofillType()来自View类,所以它应该适用于其他所有类,如TextInputEditText!
Aze*_*oth 11
我也碰到了这个.事实证明,问题是由嵌套在TextInputLayout内的EditText上的提示文本引起的.
我做了一些挖掘,并在26.0.0 Beta 2发行说明中找到了这个金块. Andorid支持发行说明2017年6月
TextInputLayout必须在onProvideAutofillStructure()上设置提示
这导致我尝试在TextInputLayout而不是嵌套的EditText上设置提示.
这解决了我的崩溃问题.例:
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Some Hint Text"
android.support.design:hintAnimationEnabled="true"
android.support.design:hintEnabled="true"
android.support.design:layout_marginTop="16dp">
<android.support.design.widget.TextInputEditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
是否可以 ?
据我所知,情况并非如此。当然,没有任何记录。
还有比这更好的方法吗?
据我所知,情况并非如此。