![](/img/trans.png)
[英]How can I make C# Xamarin.Android app run at phone start-up?
[英]How can I format phone numbers using Xamarin for Android?
如何使用Xamarin for Android格式化電話號碼? 我嘗試了這段代碼:
EditText inputField = (EditText) FindViewById(Resource.Id.editMensagemTelefone);
inputField.AddTextChangedListener(new PhoneNumberFormattingTextWatcher());
使用PhoneNumberFormattingTextWatcher()
時,請確保使用的是Android.Telephony命名空間。
參見https://developer.xamarin.com/api/type/Android.Telephony.PhoneNumberUtils/
Try this one:
_edtphonenumber=(EditText)findViewById(R.id.editText_phonenumber);
_edtphonenumber.setTypeface(trajan_pro_regular);
_edtphonenumber.addTextChangedListener(new TextWatcher() {
private boolean mFormatting; // this is a flag which prevents the stack overflow.
private int mAfter;
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// nothing to do here..
}
//called before the text is changed...
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//nothing to do here...
mAfter = after; // flag to detect backspace..
}
@Override
public void afterTextChanged(Editable s) {
// Make sure to ignore calls to afterTextChanged caused by the work done below
if (!mFormatting) {
mFormatting = true;
// using US formatting...
if(mAfter!=0) // in case back space ain't clicked...
PhoneNumberUtils.formatNumber(s,PhoneNumberUtils.getFormatTypeForLocale(Locale.US));
mFormatting = false;
}
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.