Turning off the spellchecker for an Entry tag

gregmatthewsgregmatthews ✭✭GBMember ✭✭

I have an Entry tag used for people to enter their username, which in most cases doesn't pass spellcheck, and so Android underlines it in ref. How can I stop it checking that entry?

Best Answer

Answers

  • JohnHardmanJohnHardman mod GBUniversity mod

    @gregmatthews - in a custom Entry renderer, you set the value of Control.InputType

    It's a bit-mapped value. If I remember correctly, you want to set InputTypes.TextFlagNoSuggestions

  • gregmatthewsgregmatthews ✭✭ GBMember ✭✭

    ah, ok, time to learn about customer renderers, I've dodged the need for that so far - thanks for the advice

  • JohnHardmanJohnHardman mod GBUniversity mod

    @gregmatthews - You could start with the renderer at the following link, and remove any bits not required:

    https://forums.xamarin.com/discussion/96991/how-to-remove-underline-in-entry
    
  • gregmatthewsgregmatthews ✭✭ GBMember ✭✭
    edited September 2017

    I fear you over-estimate my abilities. I've added the customerRenderer.cs to the android project, added the XAML, just a little confused on how I merge the following:
    ContentPage xmlns="http://xamarin.com/schemas/2014/forms" BackgroundColor="Gray" xmlns:local="clr-
    namespace:CustomRenderer;assembly=CustomRenderer"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="CustomRenderer.EntryLinePage"

    with my existing, my attempt below. NB: changed the namespace in the customerrenderer.cs to be SparkEVX3.Droid
    TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="CustomRenderer.EntryLinePage"
    xmlns:local="clr-namespace:SparkEVX3;assembly=CustomRenderer"
    x:Class="SparkEVX3.MainPage" BarBackgroundColor="#0e3c63" BarTextColor="White"

    it falls over as x:Class is a duplicate attribute name. I'm guessing these are naïve questions, but I'm very new to Xamarin

  • gregmatthewsgregmatthews ✭✭ GBMember ✭✭

    Thanks John - done all that, just the head of the XAML I'm struggling with now as I already have a definition for x:Class in there.
    (I've added a CustomEntry in the XAML to allow me to test, before I replace the existing one)

  • gregmatthewsgregmatthews ✭✭ GBMember ✭✭

    So, added the CustomEntry class to my project (CustomEntry.cs)
    _** using Xamarin.Forms;
    namespace SparkEVX3
    {
    public class CustomEntry : Entry
    {
    }
    }**_

    Updated my XAML:
    TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" BarBackgroundColor="#0e3c63" BarTextColor="White"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:SparkEVX3;assembly=SparkEVX3"
    x:Class="SparkEVX3.MainPage"

    and added a new Entry as:
    <local:CustomEntry Text="Custom" />

    included the customerRenderer.cs in my android project
    using Xamarin.Forms.Platform.Android;
    using Xamarin.Forms;
    using SparkEVX3;
    using SparkEVX3.Droid;
    using Android.Text;

    [assembly: ExportRenderer(typeof(CustomEntry), typeof(CustomEntryRenderer))]
    namespace SparkEVX3.Droid
    {
            public class CustomEntryRenderer : EntryRenderer
            {
                protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
                {
                    base.OnElementChanged(e);
    
                    if (Control != null)
                    {
                        this.Control.SetRawInputType(InputTypes.TextFlagNoSuggestions);
                    }
                }
            }
        }
    

    Cleaned the build, built - compiles and deploys ok, but then falls over with an error that "Type local:CustomEntry not found in XMLNS:Clr-namespace:SparkEVX3;assembly=SparkEVX3.

    Feels so close now..

  • DepechieDepechie ✭✭ BEInsider, Developer Group Leader ✭✭

    You could also use our Effects library https://github.com/FormsCommunityToolkit/FormsCommunityToolkit
    We have an effect to disable auto correct.
    Example app is included and your question can be found here https://github.com/FormsCommunityToolkit/FormsCommunityToolkit/blob/dev/Samples/Samples/Samples/Views/EffectsEntryDisableAutoCorrectPage.xaml

  • gregmatthewsgregmatthews ✭✭ GBMember ✭✭

    Update: it works if I change the Assembly name in my XAML to SparkEVX3.Android, but I thought that was shared code? and so it should be SparkEVX3?

  • JohnHardmanJohnHardman mod GBUniversity mod

    @gregmatthews - I'm not a XAML person. Hopefully somebody else can help out with that bit.

  • gregmatthewsgregmatthews ✭✭ GBMember ✭✭

    John - thanks for the support, its got me to a working solution, I may not understand why, but it works :-)

  • PaulParkinsPaulParkins ✭✭ USMember ✭✭

    This seems a bit of a long winded solution to a reasonable requirement. I think a Xamarin.Forms update (not sure which version) may have made this easier since the original post as the the Entry now has a IsSpellCheckEnabled property to control this (and also related IsTextPredictionEnabled property).
    See here for further info

    Unfortunately they don't seem to have extended these new properties to EntryCell which is where I would like to disable spell checking. Anyone have an easier suggestion than creating a custom renderer? I am hoping for an XAML only solution if possible, avoiding code behind support

  • JohnHardmanJohnHardman mod GBUniversity mod

    @PaulParkins said:
    This seems a bit of a long winded solution to a reasonable requirement. I think a Xamarin.Forms update (not sure which version) may have made this easier since the original post as the the Entry now has a IsSpellCheckEnabled property to control this (and also related IsTextPredictionEnabled property).

    Yes, this is a recent addition to XF.

    @PaulParkins said:
    Unfortunately they don't seem to have extended these new properties to EntryCell which is where I would like to disable spell checking. Anyone have an easier suggestion than creating a custom renderer? I am hoping for an XAML only solution if possible, avoiding code behind support

    You can set the Keyboard property to a keyboard that you specify. See https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.keyboard.create?view=xamarin-forms

  • PaulParkinsPaulParkins ✭✭ USMember ✭✭

    @JohnHardman said:
    You can set the Keyboard property to a keyboard that you specify. See https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.keyboard.create?view=xamarin-forms

    Thanks John. Shame I would have to resort for some code behind though, when the Xamarin developers could have added the same new properties to this variant of an Entry

  • JohnHardmanJohnHardman mod GBUniversity mod

    @PaulParkins said:

    @JohnHardman said:
    You can set the Keyboard property to a keyboard that you specify. See https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.keyboard.create?view=xamarin-forms

    Thanks John. Shame I would have to resort for some code behind though, when the Xamarin developers could have added the same new properties to this variant of an Entry

    See https://stackoverflow.com/questions/26966404/disable-autocomplete-in-xamarin-forms-pcl-xaml-page/39378157#39378157

    The XAML there is for Entry, but I would expect the same to work for EntryCell.

  • PaulParkinsPaulParkins ✭✭ USMember ✭✭

    Thanks once again John.

    Having already implemented your first suggestion, I can confirm this works.
    Since I only had 2 EntryCell's I wanted to apply this to (for URLs), I'll leave it as that even though I was pushing for a XAML solution, which you did give

Sign In or Register to comment.