【问题标题】:EditText Input FormatEditText 输入格式
【发布时间】:2019-02-09 18:21:38
【问题描述】:

我想创建一个格式如下的 EditText 字段:0000 AA。

是否可以让数字键盘出现在前4个数字然后自动产生一个空格然后出现普通键盘?

如何用 C# 做到这一点?

有人出主意吗?

【问题讨论】:

    标签: c# xamarin


    【解决方案1】:

    这应该可以解决问题:

    EditText zipcode = FindViewById<EditText>(Resource.Id.zipcode);
    zipcode.InputType = Android.Text.InputTypes.ClassNumber;
    bool numberMode = true;
    zipcode.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => {
        if(zipcode.Text.Length == 4){
            if(numberMode){
                numberMode = false;
                zipcode.Text = zipcode.Text + " ";
                zipcode.SetSelection(zipcode.Text.Length);
            }
        }
    
        if(zipcode.Text.Length > 4){
            numberMode = false;
            zipcode.InputType = Android.Text.InputTypes.ClassText;
        }
    
        if(zipcode.Text.Length <= 4){
            numberMode = true;
            zipcode.InputType = Android.Text.InputTypes.ClassNumber;
        }
    };
    

    【讨论】:

    猜你喜欢
    • 2012-07-30
    • 2020-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-05
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多