2016-07-28 63 views
0

我想在Xamarin格式的Android和iOS上禁用鍵盤上的語音到文本按鈕。如何禁用Xamarin表單中的鍵盤上的語音轉文本按鈕(聽寫按鈕)?

我的問題是,我需要實現自定義渲染,因爲我找不到適用於Android和iOS的通用代碼。

我發現下面的鏈接,以提供原生iOS

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

任何建議,將不勝感激實施。你也可以認爲我可以在Xamarin複製表格

謝謝

+0

您需要使用自定義渲染器,因爲鍵盤是特定於平臺的。 – BytesGuy

+0

謝謝你的回覆,是的,我做到了,我創建了自定義渲染器,它適用於帶有PrivateImeOptions =「nm」屬性的android,現在嘗試iOS,我不確定應該使用哪個入口屬性來禁用聽寫按鈕 –

回答

0

最後,我已經通過創建自定義渲染文本框和文本區(編者),下面的代碼爲我工作實現了這個本地平臺的方法。
在表格中,我創建了這個類。

using Xamarin.Forms; 

namespace CustomRenderer 
{ 
    public class MyEntry : Entry 
    { 
    } 
} 

在android中,我爲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"; 
      } 
     } 
    } 
} 

下面爲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; 
      } 
     } 
    } 
} 

在xaml中,我有以下語法。

<?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> 

通過上述方法,我成功地禁用了聽寫按鈕iOS和Android鍵盤。

相關問題