[英]How can I prevent Text suggestions in an Entry in Xamarin Forms?
Is it possible to disable text suggestions for a Xamarin.Forms entry?是否可以禁用 Xamarin.Forms 条目的文本建议? I expected that this is done by IsTextPredictionEnabled = false
, but this value seems to have no affect on the Entry, at least as of Xamarin Forms 5.0.0.2291.我预计这是由IsTextPredictionEnabled = false
完成的,但这个值似乎对条目没有影响,至少从 Xamarin Forms 5.0.0.2291 开始是这样。
I have created a test screen with the following code:我使用以下代码创建了一个测试屏幕:
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);
This produces the following behavior.这会产生以下行为。 Notice that both entries behave the same regardless of the IsSpellCheckEnabled
or IsTextPredictionEnabled
values.请注意,无论IsSpellCheckEnabled
或IsTextPredictionEnabled
值如何,这两个条目的行为都相同。
According to the documentation here, this should work: https://learn.microsoft.com/en-us/do.net/api/xamarin.forms.entry.istextpredictionenabled?view=xamarin.forms根据此处的文档,这应该有效: https://learn.microsoft.com/en-us/do.net/api/xamarin.forms.entry.istextpredictionenabled?view=xamarin.forms
Also here: https://learn.microsoft.com/en-us/xamarin/xamarin.forms/user-interface/text/entry也在这里: https://learn.microsoft.com/en-us/xamarin/xamarin.forms/user-interface/text/entry
Nothing came up in my searches to indicate that this is broken, so maybe I'm doing something wrong?在我的搜索中没有任何结果表明它已损坏,所以也许我做错了什么?
Use custom renderer and try to set InputTypes as TextVariationVisiblePassword,this works well on my side.Below is the code snippets for your reference.使用自定义渲染器并尝试将 InputTypes 设置为 TextVariationVisiblePassword,这对我来说效果很好。下面是代码片段供您参考。
Content = new StackLayout
{
Children = {
new MyEntry {
Text = "No SpellCheck/Prediction",
IsSpellCheckEnabled= false,
IsTextPredictionEnabled = false,
WidthRequest=300
}
},
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};
MyRenderer class:我的渲染器 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;
}
}
}
}
Document for custom renderer for your reference: https://learn.microsoft.com/en-us/xamarin/xamarin.forms/app-fundamentals/custom-renderer/entry自定义渲染器文档供您参考: https://learn.microsoft.com/en-us/xamarin/xamarin.forms/app-fundamentals/custom-renderer/entry
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.