如何使用 Xamarin for Android 格式化 phone 数字?

How can I format phone numbers using Xamarin for Android?

如何使用 Xamarin for Android 格式化 phone 数字?我试过这段代码:

EditText inputField = (EditText) FindViewById(Resource.Id.editMensagemTelefone);
inputField.AddTextChangedListener(new PhoneNumberFormattingTextWatcher());
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;
                }
            }
        });

确保在使用 PhoneNumberFormattingTextWatcher()

时使用 Android.Telephony 命名空间

https://developer.xamarin.com/api/type/Android.Telephony.PhoneNumberUtils/