项目作者: EhsanMashhadi

项目描述 :
Fully Customizable Android Country Picker
高级语言: Java
项目地址: git://github.com/EhsanMashhadi/CountryPicker.git
创建时间: 2018-11-24T14:34:51Z
项目社区:https://github.com/EhsanMashhadi/CountryPicker

开源协议:MIT License

下载


Country Picker

Powerful country picker for Android.

CountryPicker

Download

  1. Add the JitPack repository to your build file

    Add it in your project level build.gradle:

    1. allprojects {
    2. repositories {
    3. ...
    4. maven { url 'https://jitpack.io' }
    5. }
    6. }
  2. Add the dependency
    Add in in your app module level build.gradle

    1. dependencies {
    2. implementation 'com.github.EhsanMashhadi:CountryPicker:0.4.0'
    3. }

    How to use

Simple usage

  1. CountryPicker countryPicker = new CountryPicker.Builder(this).setCountrySelectionListener(new RecyclerViewAdapter.OnCountryClickListener() {
  2. @Override
  3. public void onCountrySelected(Country country) {
  4. Toast.makeText(MainActivity.this, "Selected Country: " + country.getName(), Toast.LENGTH_LONG).show();
  5. }
  6. }).build();
  7. countryPicker.show(this);

Showing flag

  1. countryPicker.showingFlag(true);

Showing dial code

  1. countryPicker.showingDialCode(true);
  1. countryPicker.enablingSearch(true);

Sort by

  • COUNTRY
  • DIALCODE
  • CODE
  • NONE
    1. countryPicker.sortBy(CountryPicker.Sort.COUNTRY);
    2. countryPicker.sortBy(CountryPicker.Sort.DIALCODE);
    3. countryPicker.sortBy(CountryPicker.Sort.CODE);
    4. countryPicker.sortBy(CountryPicker.Sort.NONE);

View type

  • DIALOG
  • BOTTOMSHEET
    1. countryPicker.setViewType(CountryPicker.ViewType.DIALOG);
    2. countryPicker.setViewType(CountryPicker.ViewType.BOTTOMSHEET);

Language

  • EN
  • FA
    1. countryPicker.setLocale(new Locale("EN"));
    2. countryPicker.setLocale(new Locale("FA"));

Preselected country

  1. countryPicker.setPreSelectedCountry("iran");

Style

  • CountryPickerLightStyle
  • CountryPickerDarkStyle
    1. countryPicker.setStyle(R.style.CountryPickerLightStyle);
    2. countryPicker.setStyle(R.style.CountryPickerDarkStyle);

For using custom theme you can declare style in style.xml

  1. <style name="CountryPickerCustomStyle">
  2. <item name="countryNameColor">@color/colorBlue</item>
  3. <item name="dialCodeColor">@color/colorBlue</item>
  4. <item name="rowBackgroundColor">@color/colorWhite</item>
  5. <item name="rowBackgroundSelectedColor">@color/colorGrey</item>
  6. </style>

and then:

  1. countryPicker.setStyle(R.style.CountryPickerCustomStyle);

Except countries

  1. List<String> countries = new ArrayList();
  2. countries.add("Germany");
  3. countries.add("Italy");
  4. countryPicker.exceptCountriesName(countries);

Set countries

  1. List<String> countries = new ArrayList();
  2. countries.add("Germany");
  3. countries.add("Italy");
  4. countryPicker.exceptCountriesName(countries);

Auto detect country

  • Locale
  • Sim
  • Network
  1. countryPicker.enableAutoDetectCountry(CountryPicker.DetectionMethod.LOCALE
  2. , country -> Toast.makeText(this, "Detected Country: " + country.getName()
  3. , Toast.LENGTH_LONG).show())