如何防止 Xamarin Forms 条目中的文本建议?
How can I prevent Text suggestions in an Entry in Xamarin Forms?
是否可以禁用 Xamarin.Forms 条目的文本建议?我预计这是由 IsTextPredictionEnabled = false
完成的,但这个值似乎对条目没有影响,至少从 Xamarin Forms 5.0.0.2291 开始是这样。
我使用以下代码创建了一个测试屏幕:
var entry1 = new Entry();
entry1.Text = "Default";
entry1.WidthRequest = 300;
entry1.IsSpellCheckEnabled = true;
entry1.IsTextPredictionEnabled = true;
absoluteLayout.Children.Add(entry1);
var entry2 = new Entry();
entry2.IsSpellCheckEnabled = false;
entry2.IsTextPredictionEnabled = false;
entry2.Text = "No SpellCheck/Prediction";
entry2.WidthRequest = 300;
entry2.Margin = new Thickness (0, 60, 0, 0);
absoluteLayout.Children.Add(entry2);
这会产生以下行为。请注意,无论 IsSpellCheckEnabled
或 IsTextPredictionEnabled
值如何,两个条目的行为都相同。
根据此处的文档,这应该有效:https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.entry.istextpredictionenabled?view=xamarin-forms
也在这里:
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/text/entry
在我的搜索中没有任何结果表明它已损坏,所以也许我做错了什么?
使用自定义渲染器并尝试将 InputTypes 设置为 TextVariationVisiblePassword,这在我的 side.Below 上运行良好 side.Below 代码片段供您参考。
Content = new StackLayout
{
Children = {
new MyEntry {
Text = "No SpellCheck/Prediction",
IsSpellCheckEnabled= false,
IsTextPredictionEnabled = false,
WidthRequest=300
}
},
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};
我的渲染器class:
[assembly: ExportRenderer(typeof(Entry), typeof(MyRenderer))]
namespace AppTestEntry.Droid
{
class MyRenderer : EntryRenderer
{
public MyRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.InputType = Android.Text.InputTypes.TextVariationVisiblePassword;
}
}
}
}
自定义渲染器文档供您参考:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/entry
是否可以禁用 Xamarin.Forms 条目的文本建议?我预计这是由 IsTextPredictionEnabled = false
完成的,但这个值似乎对条目没有影响,至少从 Xamarin Forms 5.0.0.2291 开始是这样。
我使用以下代码创建了一个测试屏幕:
var entry1 = new Entry();
entry1.Text = "Default";
entry1.WidthRequest = 300;
entry1.IsSpellCheckEnabled = true;
entry1.IsTextPredictionEnabled = true;
absoluteLayout.Children.Add(entry1);
var entry2 = new Entry();
entry2.IsSpellCheckEnabled = false;
entry2.IsTextPredictionEnabled = false;
entry2.Text = "No SpellCheck/Prediction";
entry2.WidthRequest = 300;
entry2.Margin = new Thickness (0, 60, 0, 0);
absoluteLayout.Children.Add(entry2);
这会产生以下行为。请注意,无论 IsSpellCheckEnabled
或 IsTextPredictionEnabled
值如何,两个条目的行为都相同。
根据此处的文档,这应该有效:https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.entry.istextpredictionenabled?view=xamarin-forms
也在这里: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/text/entry
在我的搜索中没有任何结果表明它已损坏,所以也许我做错了什么?
使用自定义渲染器并尝试将 InputTypes 设置为 TextVariationVisiblePassword,这在我的 side.Below 上运行良好 side.Below 代码片段供您参考。
Content = new StackLayout
{
Children = {
new MyEntry {
Text = "No SpellCheck/Prediction",
IsSpellCheckEnabled= false,
IsTextPredictionEnabled = false,
WidthRequest=300
}
},
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};
我的渲染器class:
[assembly: ExportRenderer(typeof(Entry), typeof(MyRenderer))]
namespace AppTestEntry.Droid
{
class MyRenderer : EntryRenderer
{
public MyRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.InputType = Android.Text.InputTypes.TextVariationVisiblePassword;
}
}
}
}
自定义渲染器文档供您参考:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/entry