PhoneNumberPicker is an Android library that's built upon the material TextInputLayout with country flags/code/iso2 to ease the process of entering/retrieving phone numbers.
- All countries: it has around 220+ country (including some independent ones).
- Filter by continents: you can filter countries by continent.
- Exclude country: you can exclude countries by their ISO2 code.
- Modern country flags: the flags used in the library are here rectangular-rounded-edges.
- Full phone number details: you can extract country name, code and ISO2 easily!
- Full control: you have the ability to change default country flag, text color and size, outline border color and max length of digits.
- Bottom Sheet Dialog: country list
- Search: you can search and filter countries of the bottom sheet list by name.
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.yasserakbbach:PhoneNumberPicker:1.0.0'
}
<com.yasserakbbach.phonenumberpicker.PhoneNumberPicker
android:id="@+id/phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"/>
Name | Value |
---|---|
app:textColor |
#FF0000 OR @color/red |
app:outlineBorderColor |
#FF0000 OR @color/red |
app:textSize |
18sp |
app:defaultCountry |
ma , us , gb or other ISO2 code |
app:continents |
all/africa/asia/europe/north_america/south_america/oceania |
app:maxLength |
14 |
// Get current countries list
phoneNumber.currentCountries
// Get full phone number
fun getFullPhoneNumber() : String
// Get selected country
fun getSelectedCountry() : Country
// Get countries of specifi continents
fun onlyContinents(vararg continents : Continent) : Unit
// Exclude certain countries by ISO2 criteria
fun exceptCountries(vararg iso2s : String) : Unit
// Add listener on country selection
fun setOnCountrySelected(onCountrySelected: OnCountrySelected) : Unit
// Change text color by a resource OR hexadecimal color #FF0000
fun setTextColor(@ColorRes color : Int) : Unit
fun setTextColor(color : String) : Unit
// Change the outline border color of the TextInputLayout by resource OR hexadecimal color
fun setOutlineBorderColor(@ColorRes color : Int) : Unit
fun setOutlineBorderColor(color : String) : Unit
// Change text size, the used unit is PIXEL
fun setTextSize(size : Float)
// Set default country flag by given iso2
fun setDefaultCountry(iso2 : String)
// To change max length of digits including the [+] digit!
fun setMaxLength(maxLength : Int)
- PhoneNumberKit for inspiring me to work on PhoneNumberPicker library.
- Dillinger for making it easier to create this markup file.
- Flagicons for helping me to verify country flags and get ISO2 codes.
- SVG-COMPRESSOR for compressing SVG files and making them lighter.
- FLAG ATTRIBUTES ON ANDROID
Knowledge is weapon