简体   繁体   English

如何防止 Xamarin Forms 条目中的文本建议?

[英]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.请注意,无论IsSpellCheckEnabledIsTextPredictionEnabled值如何,这两个条目的行为都相同。

在此处输入图像描述

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.

相关问题 Xamarin Forms 条目中的删除线文本 - Strikethrough text in Entry in Xamarin Forms Xamarin Forms:防止自动滚动进入焦点 - Xamarin Forms: prevent automatic scrolling on Entry Focus 如何在 Xamarin 表单中将 MainPage.xaml 中条目的文本属性访问到 MainActivity.cs? - How do I access the text property of an Entry in MainPage.xaml to MainActivity.cs in Xamarin forms? 如何以 xamarin 形式显示 html 格式的文本 - How can I show text with html format in xamarin forms Xamarin形式。 当我按下按钮时如何专注于输入的结尾? - Xamarin Forms. How I can focus on the end of entry when I press the button? 如何在将文本添加到 Xamarin Forms 中的条目之前加载视图 - How to load view before add text to entry in Xamarin Forms 如何检查条目的 Unfocus 事件是否由单击 Xamarin.Forms 中的按钮触发? - How can I check if the Unfocus event for an Entry was triggered by a button Click in Xamarin.Forms? 如何根据 xamarin.forms 中的条件更改条目的线条颜色 - How can i change the line color of an entry based on a condition in xamarin.forms 我如何检测 Xamarin Forms - 用户输入了哪个键? - How can I detect in a Xamarin Forms - Entry which key has the user typed? 如何在Xamarin.Forms条目中仅允许数字? - How Do I Allow Only Number In a Xamarin.Forms Entry?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM