A fork of the IntlPhoneInput library by RIMOTO
IntlNumberInput is a custom view for Android that allows the user to enter his phone number in an elegant and friendly way. It adds a flag dropdown to any input, automatically detects the user's country, displays a relevant placeholder and auto formats the number as they type.
Features from the original version
- Automatically format the number as the user types
- Automatically set the input placeholder to an example number for the selected country
- Selecting a country from the dropdown will update the dial code in the input
- Easy embedding as a Custom View
- Listener available to detect validity change
- Automatically detect phone number when information available
- Listen to "done" even on the keyboard
Features added in this version
- Set view style using custom XML attributes
- Custom error field
- Support for mobile and landline phone numbers
- Possibility to hide the country spinner (to benefit phone number validation and formatting for a single country)
Download via Gradle:
compile 'com.juxbzh:intlphoneinput:1.0.7'
or Maven:
<dependency>
<groupId>com.juxbzh</groupId>
<artifactId>intlphoneinput</artifactId>
<version>1.0.7</version>
</dependency>
It's easy like 1-2-3!
- Add the view to your layout XML:
<net.rimoto.intlphoneinput.IntlPhoneInput
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/my_phone_input" />
- Find it in your java
IntlPhoneInput phoneInputView = (IntlPhoneInput) findById(R.id.my_phone_input);
- Check for validity and get the number!
String myInternationalNumber;
if(phoneInputView.isValid()) {
myInternationalNumber = phoneInputView.getNumber();
}
- Customize appearance via XML
<net.rimoto.intlphoneinput.IntlPhoneInput
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/component_default_spacing"
app:textColor="#FF0000"
app:textColorHint="#FFBBBB"
app:countryNameColor="@color/colorPrimary"
app:dialCodeColor="@color/colorAccent"
app:textSize="20sp"/>
For more details see attached sample project