Material design components to pick country.
repositories {
google()
jcenter()
}
dependencies {
implementation "com.hendraanggrian.appcompat:countrypicker:$version"
implementation "com.hendraanggrian.appcompat:countrypicker-sheet:$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()
CountryPicker
itself is a LinearLayout
that may be used independently with XML or programatically.
By default, country flags are represented in emoji to achieve lowest library size.
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.