-
-
Notifications
You must be signed in to change notification settings - Fork 29
Change Flags
Harsh B. Bhakta edited this page Oct 16, 2021
·
3 revisions
When png flags are packed with library, it increases library size and eventually it increases your project size (even for project that does not want to use those flags). To avoid this, Country Picker
library packs only text based Emoji flags by default. You can change flags by providing a FlagPack
. This FlagPack can be a custom one OR one of the library provided FlagPacks.
1. If you wish you use library provided flag pack then pick one of the following (well there is only one additional right now)
- a. FlagPack1
2. Use custom flag pack
- For reference, you will need to create a data object similar to library provided flag packs i.e. FlagPack1 Source
- Let's call it
CustomFlagPack
. - Create a variable for missing flag placeholder image resource
val missingFlagPlaceHolder: Int = R.drawable.flag_transparent
. This will be used for flag that your flag pack does not have - Create a
Map<String,Int>
namedalpha2ToFlag
where key will be alpha2 code of country and corresponding value will be flag image resource like this. - Make Flag Image Provider using,
val flagProvider = CPFlagImageProvider(CustomFlagPack.alpha2ToFlag, CustomFlagPack.missingFlagPlaceHolder)
- Now that you have flagProvider ready, you can apply it to CountryPickerView, CountryPickerDialog or CountryList.
- For
CountryPickerView
, apply usingcountryPickerView.changeFlagProvider(flagProvider)
. This will be automatically applied to the dialog launched on click. - For
CountryPickerDialog
, pass it ascpFlagProvider
tocontext.launchCountryPickerDialog(cpFlagProvider = flagProvider)
. Read More - For
CountryList
, pass it ascpFlagProvider
torecyclerView.loadCountries(cpFlagProvider = flagProvider)
. Read More