PhoneEditText Android
An Android EditText component that automatically detects and sets country dial codes for phone number input fields, eliminating the need for manual country selection dropdowns.
Tech Stack
What is PhoneEditText?
PhoneEditText is an Android library that simplifies phone number input by automatically detecting and setting the user’s country dial code. It eliminates the need for clunky dropdown menus or manual country selection, providing a seamless user experience.
Key Features
- Automatic Country Detection: Identifies the user’s country from SIM card or network and sets the appropriate dial code
- No Dropdown Lists: Clean, minimal UI without country selection menus
- TextInputEditText Support: Fully compatible with Material Design’s TextInputLayout
- Programmatic Access: Easily retrieve the dial code via
getDIAL_CODE()method - User Flexibility: Users can still manually change the dial code if needed
Installation
Via JitPack
Add JitPack to your project-level build.gradle:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency to your app-level build.gradle:
dependencies {
implementation 'com.google.android.material:material:1.1.0-alpha09'
implementation 'com.github.amannirala13:PhoneEditText-Android:1.1.1'
}
Usage
XML Layout
<com.asdev.phoneedittext.PhoneEditText
android:id="@+id/phoneInput"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Get Dial Code Programmatically
import com.asdev.phoneedittext.PhoneEditText;
PhoneEditText phoneInput = findViewById(R.id.phoneInput);
String dialCode = phoneInput.getDIAL_CODE(); // Returns dial code as String
Advantages
- No dropdown lists cluttering the UI
- No user-based inputs required for country selection
- No hardcoded/predictive dial code definitions
- Users can override the auto-detected code
- Full Material Design TextInputEditText support
Limitations
- Defaults to +91 (India) when the device is connected via WiFi (as carrier info isn’t available)