c# - 禁用默认 Android 键盘上的按键

标签 c# android xamarin xamarin.forms android-softkeyboard

我的 Xamarin 应用程序主页上有一个 Entry 控件,用于输入一个人的年龄。我已将键盘设置为 Keyboard="Numberic"

但是,这会造成混淆,因为至少对于 Android 而言,“完成”键在退格键下方,但在设置键和 .- 键上方。这意味着当用户试图按下“完成”时,他们忘记了该键并不像您预期​​的那样位于右下角,并且他们一直错误地按下设置键并进入他们的手机设置,这有点烦人,这是可以理解的。

是否可以禁用设置键和 .- 键,或者调换它们的位置?我不希望它成为可能,那么在这种情况下,我是否有其他方法可以解决这个问题?

用于阐明我的意思的屏幕截图 - 是否可以移动或禁用带有设置齿轮和“.-”的键,以防止用户打开他们的手机设置并输入负数/小数?

enter image description here

最佳答案

我没有使用过 C#,也从未使用过 Android,但是从大多数语言中删除字符串中的字符的想法通常很简单。

基于我们在评论中的小讨论和一些研究;我相信这就是您要从用户在您的应用程序中输入的 EditText 字段中删除不需要的值的方法:

var editText = FindViewById<EditText> (Resource.Id.editText);

editText.TextChanged += (object sender, Android.Text.TextChangedEventArgs et) => {
    //step 1 grab editText value
    String newString = et.Text.ToString(); 

    //step 2 replace unwanted characters (currently '.' & '-')
    newString = newString.Replace(".", "").Replace("-", "");

    //step 3 set the editText field to the updated string
    editText.Text = newString;

};

资源: https://github.com/xamarin/recipes/tree/master/Recipes/android/controls/edittext/capture_user_input_text

我还没有找到一种方法来更改 Android 的默认键盘,以便您可以删除不需要的键(即设置键)或重新排序它们,所以我仍然认为如果您决定必须这样做,您需要为应用程序构建自定义键盘。

关于c# - 禁用默认 Android 键盘上的按键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50835976/

相关文章:

c# - Linq 到 SQL : delete record with generic type method

c# - ASP.NET Core Razor Page 多路径路由

android - ARM64 在 iOS 上使用气体?

android - GLSurfaceView 渲染器,如何强制重新创建表面?

c# - 如何将 CollectionView SelectedItems 绑定(bind)到列表?

c# - Chrome 在下载时修改长文件名(使用 c# FileContentResult)

c# - 如何将更改从开发上传到生产

android - 来自数组的 ReplySubject

Xamarin 表单条目 : Use comma as decimal separator

c# - 使用匿名异步方法调用方法时,xUnit 测试挂起/死锁