我知道Android从某些版本可以检测到该字段是输入用户名/密码/姓氏/名字的字段吗?
但是我需要在Xamarin形式中做些什么才能实现它呢?
发布于 2018-06-21 04:53:10
在API-27+ (Oreo+)中,最好使用带有自动填充框架的AutoCompleteTextView,但不是绝对需要的。
注意:Xamarin.Forms目前(直到3.0.x)还没有在任何内置窗体控件中实现Android原生AutoCompleteTextView,但是您可以只使用Entry控件(在Android上实现为TextView )。
在基于Android的TextView或AutoCompleteTextView上,您应该以编程方式调用:
* SetAutofillHints
* ImportantForAutofill示例:
usernameView.SetAutofillHints(new string[2] {"emailAddress", "userName"});
usernameView.ImportantForAutofill = ImportantForAutofill.Yes;注意:在原生Xamarin.Android中,您可以只在AXML布局中设置这些属性。
回复:https://codelabs.developers.google.com/codelabs/optimize-autofill/#0
注意:查看Android文档中关于AutofillHints字符串应该设置为什么的基础知识...
在Xamarin.Forms中,您可以通过自定义渲染器或效果来执行此操作:
Xamarin.Forms自动填充安卓特效示例:
[assembly: ResolutionGroupName("EffectsAutoFill")]
[assembly: ExportEffect(typeof(AutoFillUserNameEffect), "AutoFillUserNameEffect")]
namespace Effects
{
public class AutoFillUserNameEffect : PlatformEffect
{
protected override void OnAttached()
{
var textView = (TextView)Control;
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
{
textView.SetAutofillHints(new string[2] { "emailAddress", "userName" });
textView.ImportantForAutofill = ImportantForAutofill.Yes;
}
protected override void OnDetached()
{
}
}
}用法:
emailEntry.Effects.Add(Effect.Resolve("EffectsAutoFill.AutoFillUserNameEffect"));你的表单应用程序现在将触发用户在其设备上启用的所有自动填充服务:谷歌、LastPass等。(当然,这取决于用户是否启用一个...)
输出:

https://stackoverflow.com/questions/50943371
复制相似问题