The PhoneNumberFormattingTextWatcher(String countryCode)
is hidden API, as you can see from the @hide
tag in the javadoc. In other words: that particular constructor is not part of the SDK.
What's wrong with PhoneNumberFormattingTextWatcher?
-
05-08-2022 - |
题
In my app I'm trying to format the phone number typed in an EditText
. For that I'm using a PhoneNumberFormattingTextWatcher.
I'm having issues with this class. Trying to use the constructor PhoneNumberFormattingTextWatcher(String countryCode)
doesn't compile. I can't find it in the documentation but it's definitely in the sdk (see the code source).
What's wrong with that class?
解决方案
其他提示
I highly suggest you to use PhoneNumberUtils
to format a phone number.
https://developer.android.com/reference/android/telephony/PhoneNumberUtils.html
And especially these two methods:
formatNumber(String source)
Breaks the given number down and formats it according to the rules for the country the number is from.formatNumber(Editable text, int defaultFormattingType)
Formats a phone number in-place.
According to the documentation, this CTOR is available from API21 , so you can either copy the code for pre-Lollipop, or use it when you can:
不隶属于 StackOverflow