Skip to content

Android Country Picker is a Kotlin-first, flexible and powerful Android library that allows to integrate Country Picker with just a few lines.

License

Notifications You must be signed in to change notification settings

hbb20/AndroidCountryPicker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

afd480a · May 1, 2023
Jul 31, 2021
Mar 13, 2023
Mar 13, 2023
Mar 13, 2023
Mar 13, 2023
Mar 13, 2023
Sep 2, 2020
Mar 13, 2023
Jan 16, 2021
May 16, 2022
Sep 20, 2019
Feb 21, 2022
Mar 13, 2023
Sep 12, 2019
Dec 24, 2019
Feb 26, 2022
Sep 12, 2019
Sep 12, 2019
Jul 31, 2021

Repository files navigation

visitors Add

Country Picker View Country Picker Dialog

1. Add dependency

  •     dependencies {
          implementation 'com.hbb20:android-country-picker:X.Y.Z'
         }
  • For latest version, Add

2. Decide your use-case

Default Country Picker View i. add following to your XML layout
   <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

Custom Country Picker View

i. Read how to create your Custom Country Picker View

Launch Country Picker Dialog i. add following to your Activity/Fragment
   context.launchCountryPickerDialog { selectedCountry: CPCountry? ->
     // your code to handle selected country
   }

ii. Read More about CountryPicker Dialog and available configuration

Load countries in RecyclerView i. add following to your Activity/Fragment
   recyclerView.loadCountries { selectedCountry: CPCountry -> 
     // your code to handle selected country
   }

ii. Read More about Country List and available configuration

Credits