0

I want to disable Voice to Text button on keyboard in Xamarin forms both for android and iOS.

My question is, do I need to implement custom render as I couldn't find generic code to work for both Android and iOS.

I have found below link for implementing in native iOS

Disable Dictation button on the keyboard of iPhone 4S / new iPad

Any suggestions would be greatly appreciated. You can also suggest native platform approaches that I can replicate in Xamarin Forms

Thank you

Community
  • 1
  • 1
  • You would need to use a custom renderer as the keyboard is platform specific. – BytesGuy Jul 29 '16 at 12:07
  • Thank you for your reply, yes I did that, I had created custom renderer and it's working for android with PrivateImeOptions="nm" property and trying for iOS now and I am not sure which entry property I should use to disable dictation button – vinod kumar Jul 29 '16 at 12:30

1 Answers1

0

Finally I had achieved this by creating Custom render for Textbox and Text area(Editor), below code worked for me.
In forms, I have created this class.

using Xamarin.Forms;

namespace CustomRenderer
{
    public class MyEntry : Entry
    {
    }
}

In android I created custom render for MyEntry.

using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using CustomRenderer;
using CustomRenderer.Android;

[assembly: ExportRenderer (typeof(MyEntry), typeof(MyEntryRenderer))]
namespace CustomRenderer.Android
{
    class MyEntryRenderer : EntryRenderer
    {
        protected override void OnElementChanged (ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged (e);

            if (Control != null) {
                Control.SetBackgroundColor (global::Android.Graphics.Color.LightGreen);
                Control.PrivateImeOptions = "nm";
            }
        }
    }
}

Below render for iOS.

using Xamarin.Forms.Platform.iOS;
using Xamarin.Forms;
using UIKit;
using CustomRenderer;
using CustomRenderer.iOS;

[assembly: ExportRenderer (typeof(MyEntry), typeof(MyEntryRenderer))]
namespace CustomRenderer.iOS
{
    public class MyEntryRenderer : EntryRenderer
    {
        protected override void OnElementChanged (ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged (e);

            if (Control != null) {
                // do whatever you want to the UITextField here!
                Control.BackgroundColor = UIColor.FromRGB (204, 153, 255);
                Control.BorderStyle = UITextBorderStyle.Line;
                Control.KeyboardType = UIKeyboardType.EmailAddress; 
            }
        }
    }
}

In xaml I had following syntax.

<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:CustomRenderer;assembly=CustomRenderer"
    x:Class="CustomRenderer.MainPageXaml">
    <StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
        <Label Text="Hello, Custom Renderer!" />
        <local:MyEntry Text="In Shared Code" /> 
    </StackLayout>
</ContentPage>

With above approach I had successfully disabled the Dictation button iOS and Android keyboards.