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?
Copy the CustomEntry class into your PCL project
Change your code where you currently use Entry to use CustomEntry, but only for those Entry views where you don't want the spell-checking
Copy the CustomEntryRenderer.cs into your Android project
Remove the following lines:
GradientDrawable gd = new GradientDrawable (); gd.SetColor (global::Android.Graphics.Color.Transparent); this.Control.SetBackgroundDrawable (gd); Control.SetHintTextColor(ColorStateList.ValueOf(global::Android.Graphics.Color.White));
I think the following line is ok as is, although I do it slightly differently:
this.Control.SetRawInputType (InputTypes.TextFlagNoSuggestions);
Answers
@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
ah, ok, time to learn about customer renderers, I've dodged the need for that so far - thanks for the advice
@gregmatthews - You could start with the renderer at the following link, and remove any bits not required:
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
@gregmatthews -
Copy the CustomEntry class into your PCL project
Change your code where you currently use Entry to use CustomEntry, but only for those Entry views where you don't want the spell-checking
Copy the CustomEntryRenderer.cs into your Android project
Remove the following lines:
I think the following line is ok as is, although I do it slightly differently:
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)
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;
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..
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
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?
@gregmatthews - I'm not a XAML person. Hopefully somebody else can help out with that bit.
John - thanks for the support, its got me to a working solution, I may not understand why, but it works :-)
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
Yes, this is a recent addition to XF.
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.
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