Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Android Kotlin library to parse and format international phone numbers. Country code picker.

License

NotificationsYou must be signed in to change notification settings

ibrahimsn98/PhoneNumberKit

Repository files navigation

AndroidKotlin library to parse and format international phone numbers. Based on Google's libphonenumber library.

Features

Features
☎️Validate, normalize and extract the elements of any phone number string.
🎯Convert raw phone number to formatted phone number string.
🔍Automatically detects country flag of the phone number.
🔖Country code selection bottom sheet.
📌Convert country codes to country names and vice versa.
🇹🇷Get country flag icon for given iso2 code.

Usage

Create a phoneNumberKit instance and attach it to an editTextLayout. That's all you have to do.

val phoneNumberKit=PhoneNumberKit.Builder(this)    .setIconEnabled(true)    .admitCountries(listOf("tr","ca","de"))// List only those county formats    .excludeCountries(listOf("tr","ca"))// Exclude those county formats    .build()phoneNumberKit.attachToInput(textField,"tr")// ORphoneNumberKit.attachToInput(textField,1)

To setup with country code selection bottom sheet

phoneNumberKit.setupCountryPicker(this)// Requires activity context

To get an example phone number for giveniso2 code

val exampleNumber= phoneNumberKit.getExampleNumber("tr")

To parse raw text to phone number and receive country code, national number

val parsedNumber= phoneNumberKit.parsePhoneNumber(    number="1266120000",    defaultRegion="us")parsedNumber?.nationalNumberparsedNumber?.countryCodeparsedNumber?.numberOfLeadingZeros

To convert raw text to formatted phone number string

val formattedNumber= phoneNumberKit.formatPhoneNumber(    number="1266120000",    defaultRegion="us")

To receive a countryflag icon for given iso2 code

val flag= phoneNumberKit.getFlagIcon("ca")

Usage with Custom Item Layout

Add your custom item layout resource as a parameter

phoneNumberKit.setupCountryPicker(this,R.layout.my_item_layout, searchEnabled=true)

You need to use below view ids in your layout file

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:paddingVertical="12dp"android:paddingHorizontal="18dp"android:clickable="true"android:focusable="true"android:background="?android:attr/selectableItemBackground">    <ImageViewandroid:id="@+id/imageViewFlag"android:layout_width="22dp"android:layout_height="22dp" />    <TextViewandroid:id="@+id/textViewName"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:layout_marginStart="16dp"android:layout_marginEnd="16dp"android:singleLine="true"android:maxLines="1"android:ellipsize="end"android:textSize="16sp"android:textColor="#232425" />    <TextViewandroid:id="@+id/textViewCode"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="16sp"android:textColor="#838383" /></LinearLayout>

Demo

Country Code PickerFormat ExampleFormat Example

Installation

Follow me on Twitter@ibrahimsn98

Step 1. Add the JitPack repository to your build file

allprojects {repositories {...maven { url 'https://jitpack.io' }}}

Step 2. Add the dependency

dependencies {    implementation 'com.github.ibrahimsn98:PhoneNumberKit:2.0.6'}

Checklist

  • Search for country codes
  • Custom list item layout support
  • Better performance with coroutines
  • Phone number validation indicator
  • Dark theme
  • Tests

Conception

License

PhoneNumberKit is available under the Apache license. See theLICENSE file for more info.

About

Android Kotlin library to parse and format international phone numbers. Country code picker.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors8

Languages


[8]ページ先頭

©2009-2025 Movatter.jp