Material design components to pick country.
- Emoji country flags to achieve lowest library size, with options to customize.
- Search box, locate button, and fast scroller.
repositories {
google()
mavenCentral()
}
dependencies {
implementation "com.hendraanggrian.material:countrypicker:$version"
}
Use CountryPickerDialog.Builder
to build or show CountryPickerDialog
.
new CountryPickerDialog.Builder(context)
.setOnSelectedListener(new CountryPicker.OnSelectedListener() {
@Override
public void onSelected(@NonNull Country country) {
// do something
}
})
.show();
No builder here, create traditionally.
BottomSheetDialog dialog = new CountryPickerSheetDialog(context);
dialog.setOnSelectedListener(new CountryPicker.OnSelectedListener() {
@Override
public void onSelected(@NonNull Country country) {
// do something
}
});
dialog.show()
To use custom flag images, have a drawable with name format
flag_{2-digit iso code}
in your project. For example if you want to display US
flag, the drawable name should be flag_us
.
See Country.java for all available country codes.