Powerful country picker for Android.
- Add the JitPack repository to your build file
Add it in your project level build.gradle:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency Add in in your app module level build.gradle
dependencies {
implementation 'com.github.EhsanMashhadi:CountryPicker:0.4.0'
}
CountryPicker countryPicker = new CountryPicker.Builder(this).setCountrySelectionListener(new RecyclerViewAdapter.OnCountryClickListener() {
@Override
public void onCountrySelected(Country country) {
Toast.makeText(MainActivity.this, "Selected Country: " + country.getName(), Toast.LENGTH_LONG).show();
}
}).build();
countryPicker.show(this);
countryPicker.showingFlag(true);
countryPicker.showingDialCode(true);
countryPicker.enablingSearch(true);
- COUNTRY
- DIALCODE
- CODE
- NONE
countryPicker.sortBy(CountryPicker.Sort.COUNTRY);
countryPicker.sortBy(CountryPicker.Sort.DIALCODE);
countryPicker.sortBy(CountryPicker.Sort.CODE);
countryPicker.sortBy(CountryPicker.Sort.NONE);
- DIALOG
- BOTTOMSHEET
countryPicker.setViewType(CountryPicker.ViewType.DIALOG);
countryPicker.setViewType(CountryPicker.ViewType.BOTTOMSHEET);
- EN
- FA
countryPicker.setLocale(new Locale("EN"));
countryPicker.setLocale(new Locale("FA"));
countryPicker.setPreSelectedCountry("iran");
- CountryPickerLightStyle
- CountryPickerDarkStyle
countryPicker.setStyle(R.style.CountryPickerLightStyle);
countryPicker.setStyle(R.style.CountryPickerDarkStyle);
For using custom theme you can declare style in style.xml
<style name="CountryPickerCustomStyle">
<item name="countryNameColor">@color/colorBlue</item>
<item name="dialCodeColor">@color/colorBlue</item>
<item name="rowBackgroundColor">@color/colorWhite</item>
<item name="rowBackgroundSelectedColor">@color/colorGrey</item>
</style>
and then:
countryPicker.setStyle(R.style.CountryPickerCustomStyle);
List<String> countries = new ArrayList();
countries.add("Germany");
countries.add("Italy");
countryPicker.exceptCountriesName(countries);
List<String> countries = new ArrayList();
countries.add("Germany");
countries.add("Italy");
countryPicker.exceptCountriesName(countries);
- Locale
- Sim
- Network
countryPicker.enableAutoDetectCountry(CountryPicker.DetectionMethod.LOCALE
, country -> Toast.makeText(this, "Detected Country: " + country.getName()
, Toast.LENGTH_LONG).show())