https://github.com/malekkamel/phone-field
https://github.com/malekkamel/phone-field
android android-library edittext java-8 phone phonenumber
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/malekkamel/phone-field
- Owner: MalekKamel
- Created: 2018-03-21T16:48:23.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-28T12:38:03.000Z (about 7 years ago)
- Last Synced: 2025-01-27T15:43:32.643Z (8 months ago)
- Topics: android, android-library, edittext, java-8, phone, phonenumber
- Language: Java
- Size: 3.43 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PhoneFiled
##### PhoneFiled is an easy way to select country phone and validate the entered number.
##### It's a fork from https://github.com/lamudi-gmbh/android-phone-field.
##### I added a search and arabic names for countries.# Installation
```gradle
repositories {
maven {
url "https://dl.bintray.com/shabankamel/android"
}
}
dependencies {
implemetation 'com.sha.kamel:phonefield:1.2.1@aar'
}
```# Usage:
```java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);final PhoneInputLayout phoneInputLayout = findViewById(R.id.phone_input_layout);
final PhoneEditText phoneEditText = findViewById(R.id.edit_text);// Must call init, else, you'll get IllegalStateException when clicking country view.
phoneInputLayout.init(this);
phoneEditText.init(this);final Button button = findViewById(R.id.submit_button);
phoneInputLayout.setHint(R.string.phone_hint);
phoneInputLayout.setDefaultCountry("EG");phoneEditText.setHint(R.string.phone_hint);
phoneEditText.setDefaultCountry("FR");button.setOnClickListener(v -> {
boolean valid = true;
if (phoneInputLayout.isValid()) {
phoneInputLayout.setError(null);
} else {
phoneInputLayout.setError(getString(R.string.invalid_phone_number));
valid = false;
}if (phoneEditText.isValid()) {
phoneEditText.setError(null);
} else {
phoneEditText.setError(getString(R.string.invalid_phone_number));
valid = false;
}if (valid) {
toast(R.string.valid_phone_number);
} else {
toast(R.string.invalid_phone_number);
}
});
}private void toast(int res) {
Toast.makeText(this, res, Toast.LENGTH_LONG).show();
}
```### See 'app' module for the full code.
# License
## Apache license 2.0