Android Country Picker is a Kotlin-first, flexible and powerful Android library that allows to integrate Country Picker with just a few lines.
Country Picker View | Country Picker Dialog |
---|---|
<com.hbb20.CountryPickerView
android:id="@+id/countryPicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
ii. modify view / dialog / list config in activity or fragment
private fun setupCountryPickerView() {
val countryPicker = findViewById<CountryPickerView>(R.id.countryPicker)
// Modify CPViewConfig if you need. Access cpViewConfig through `cpViewHelper`
countryPicker.cpViewHelper.cpViewConfig.viewTextGenerator = { cpCountry: CPCountry ->
"${cpCountry.name} (${cpCountry.alpha2})"
}
// make sure to refresh view once view configuration is changed
countryPicker.cpViewHelper.refreshView()
// Modify CPDialogConfig if you need. Access cpDialogConfig through `countryPicker.cpViewHelper`
// countryPicker.cpViewHelper.cpDialogConfig.
// Modify CPListConfig if you need. Access cpListConfig through `countryPicker.cpViewHelper`
// countryPicker.cpViewHelper.cpListConfig.
// Modify CPRowConfig if you need. Access cpRowConfig through `countryPicker.cpViewHelper`
// countryPicker.cpViewHelper.cpRowConfig.
}
ii. Read More about Country Picker View and available configuration
i. Read how to create your Custom Country Picker View
context.launchCountryPickerDialog { selectedCountry: CPCountry? ->
// your code to handle selected country
}
ii. Read More about CountryPicker Dialog and available configuration
recyclerView.loadCountries { selectedCountry: CPCountry ->
// your code to handle selected country
}
ii. Read More about Country List and available configuration