countrypicker
countrypicker copied to clipboard
Material design components to pick country
CountryPicker
Material design components to pick country.
Download
repositories {
google()
jcenter()
}
dependencies {
implementation "com.hendraanggrian.appcompat:countrypicker:$version"
implementation "com.hendraanggrian.appcompat:countrypicker-sheet:$version"
}
Usage
Dialog
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();
Bottom sheet
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()
Inflate manually
CountryPicker
itself is a LinearLayout
that may be used independently with XML or programatically.
Country flags
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.