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.
***Full Demo Video - https://youtu.be/vDL6gBtltng ***
- Formatting the number as the user types Aautomatically
- 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
- Typing a different dial code will automatically update the displayed flag
- 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
- More..
Download via Gradle or Maven:
compile 'net.rimoto:intlphoneinput:1.0.1'
or Maven:
<dependency>
<groupId>net.rimoto</groupId>
<artifactId>intlphoneinput</artifactId>
<version>1.0.1</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" />
- Set text size, text color and flag padding:
<net.rimoto.intlphoneinput.IntlPhoneInput
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:textSize="14sp"
app:textColor="#000000"
app:flagPaddingBottom="4dp"
app:flagPaddingEnd="4dp"
app:flagPaddingStart="4dp"
app:flagPaddingTop="4dp"
app:flagPaddingBottom="4dp"
android:id="@+id/my_phone_input" />
- Add 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();
}
-
boolean isValid()
-
void setEnabled(boolean enabled)
-
void setOnValidityChange(IntlPhoneInputListener listener)
public interface IntlPhoneInputListener { void done(View view, boolean isValid); }
This simple structure allows you to use lambda expression! (with retrolambda):
mIntlPhoneInput.setOnValidityChange((view, isValid) -> { if(isValid) {...} }
-
void setOnKeyboardDone(IntlPhoneInputListener listener)
-
void hideKeyboard()
-
void setDefault()
- Set default number: if can detect line by permission(requiresandroid.permission.READ_PHONE_STATE
), else- example number for country as hint(detect by SIM info if has permission, else by locale). This method automatically invoked on init -
void setEmptyDeafult(String iso)
- Set example hint for iso -
void setEmptyDefault()
- Set example hint by locale -
void setNumber(String number)
- Set number, number in E.164 format(i.e.+972501234567
) -
String getNumber()
orString getText()
- Get number in E.164 format
- Inspired by intl-tel-input for jQuery
- Flag images from region-flags
- Original country data from mledoze's World countries in JSON, CSV and XML
- Formatting/validation/example number code from libphonenumber
Thanks to our sponsors for this project:
Copyright 2015 Rimoto LTD, AlmogBaku
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.