【发布时间】:2019-02-09 18:21:38
【问题描述】:
我想创建一个格式如下的 EditText 字段:0000 AA。
是否可以让数字键盘出现在前4个数字然后自动产生一个空格然后出现普通键盘?
如何用 C# 做到这一点?
有人出主意吗?
【问题讨论】:
我想创建一个格式如下的 EditText 字段:0000 AA。
是否可以让数字键盘出现在前4个数字然后自动产生一个空格然后出现普通键盘?
如何用 C# 做到这一点?
有人出主意吗?
【问题讨论】:
这应该可以解决问题:
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;
}
};
【讨论】: