<Entry Keyboard="Numeric"/>
键不起作用(它不键入)。
我在网上进行了一些挖掘,找到了一些解决方案,但没有任何解决方案对我有用。Solution1通过将此代码添加到
.-
(在App()
)中,将应用程序文化迫使PT-BR(因为我的电话系统语言是巴西葡萄牙语):
App.xaml.cs
但没有变化。 SULOTIE2
为条目的自定义渲染器上设置输入类型:
private void SetCultureToPTBR()
{
CultureInfo br = new CultureInfo("pt-BR");
CultureInfo.DefaultThreadCurrentCulture = br;
}
this方法将[assembly: ExportRenderer(typeof(Entry), typeof(CustomEntryRenderer))]
namespace AppCoperNitro.Droid.CustomRenderers
{
public class CustomEntryRenderer : EntryRenderer
{
public CustomEntryRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control == null || e.NewElement == null)
return;
this.Control.KeyListener = DigitsKeyListener.GetInstance(true, true);
this.Control.InputType = Android.Text.InputTypes.ClassNumber | Android.Text.InputTypes.NumberFlagDecimal;
}
}
}
键更改为逗号键,并且有点可行(它键入A。),但是小数点位置被忽略(如果我键入2.3,则应用程序将其接收为23)。
Solution3
this溶液,但结果与溶液2相同。 我还尝试将这些解决方案及其差异结合起来,但没有任何作用。我什至不在乎该条目是否显示逗号或点,我只需要正确接收的小数号。
我们可以改变方式。根据您的解决方案2,该条目可以输入
.-
,因此您可以在该条目的未关注事件中做一些事情。例如://使用GABIC的代码
.
然后将事件添加到XAML中:
private void Entry_Unfocused(object sender, FocusEventArgs e)
{
Entry entry = sender as Entry;
if (entry.Text.Length > 0 && Android.OS.Build.Manufacturer.Equals("Samsung", StringComparison.CurrentCultureIgnoreCase))
{
string a = entry.Text.Replace('.', ',');
entry.Text = a;
}
}
它是一个定制器,只需将其放入您的Android项目中,它将在每个条目中使用KeyboardType =Numeric.
自动激活。