{"id":13643267,"url":"https://github.com/zaaach/CityPicker","last_synced_at":"2025-04-21T01:32:19.510Z","repository":{"id":41165437,"uuid":"52658839","full_name":"zaaach/CityPicker","owner":"zaaach","description":":fire::fire::fire:城市选择、定位、搜索及右侧字母导航，类似美团 百度糯米 饿了么等APP选择城市功能","archived":false,"fork":false,"pushed_at":"2021-07-07T06:55:07.000Z","size":14120,"stargazers_count":3124,"open_issues_count":44,"forks_count":588,"subscribers_count":52,"default_branch":"master","last_synced_at":"2025-04-14T12:18:27.917Z","etag":null,"topics":["city","indexbar","location","recyclerview"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zaaach.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-27T09:11:27.000Z","updated_at":"2025-04-06T12:18:42.000Z","dependencies_parsed_at":"2022-07-21T04:49:35.175Z","dependency_job_id":null,"html_url":"https://github.com/zaaach/CityPicker","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaaach%2FCityPicker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaaach%2FCityPicker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaaach%2FCityPicker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaaach%2FCityPicker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zaaach","download_url":"https://codeload.github.com/zaaach/CityPicker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877968,"owners_count":21176244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["city","indexbar","location","recyclerview"],"created_at":"2024-08-02T01:01:44.923Z","updated_at":"2025-04-21T01:32:16.539Z","avatar_url":"https://github.com/zaaach.png","language":"Java","funding_links":[],"categories":["选择器(Picker)","Java"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"art/header.png\"\u003e\n\u003c/p\u003e\n\n# CityPicker\n\n[![Platform](https://img.shields.io/badge/platform-android-green.svg)](http://developer.android.com/index.html) [![API](https://img.shields.io/badge/API-14%2B-yellow.svg?style=flat)](https://android-arsenal.com/api?level=14)\n\n现在使用较多的类似美团、外卖等APP的城市选择界面，**一行代码搞定**，就是这么简单粗暴！！！\n\n**Tips:**（旧版本1.x）会报高德定位jar包冲突，推荐使用2.x版本。\n\n#### 主要功能：\n\n-   字母悬浮栏\n-   指定热门城市\n-   自定义动画效果\n-   自定义主题\n-   名称或拼音搜索\n-   返回城市名、code等数据\n-   提供定位接口，解耦定位SDK\n\n# Preview\n\n![image](https://github.com/zaaach/CityPicker/raw/master/art/screen.gif) ![image](https://github.com/zaaach/CityPicker/raw/master/art/screen1.gif)\n![image](https://github.com/zaaach/CityPicker/raw/master/art/screen2.gif)\n\n# APK\n\n下载[demo.apk](https://github.com/zaaach/CityPicker/raw/master/art/demo.apk)体验.\n\n# Download\n\n**1：** 项目根目录的build.gradle添加如下配置：\n\n```groovy\nallprojects {\n\trepositories {\n\t\t...\n\t\tmaven { url 'https://jitpack.io' }\n\t}\n}\n```\n\n**2：** app添加依赖：\n\n```groovy\ndependencies {\n\t implementation 'com.github.zaaach:CityPicker:x.y.z'\n}\n```\n\n记得把`x.y.z`替换为[![jitpack](https://jitpack.io/v/zaaach/CityPicker.svg)](https://jitpack.io/#zaaach/CityPicker)中的数字\n\n# Usage\n\n`CityPicker` 基于`DialogFragment` 实现，已提供定位接口，需要APP自身实现定位。\n\n### 基本使用：\n\n#### Step1:\n\n在`manifest.xml`中给使用`CityPicker` 的`activity`添加主题`android:theme=\"@style/DefaultCityPickerTheme\"`\n\n```xml\n\u003cactivity android:name=\".MainActivity\" android:theme=\"@style/DefaultCityPickerTheme\"\u003e\n  ......\n\u003c/activity\u003e\n```\n\n#### Step2:\n\n注意：热门城市使用`HotCity` ，定位城市使用`LocatedCity` \n\n```java\nList\u003cHotCity\u003e hotCities = new ArrayList\u003c\u003e();\nhotCities.add(new HotCity(\"北京\", \"北京\", \"101010100\")); //code为城市代码\nhotCities.add(new HotCity(\"上海\", \"上海\", \"101020100\"));\nhotCities.add(new HotCity(\"广州\", \"广东\", \"101280101\"));\nhotCities.add(new HotCity(\"深圳\", \"广东\", \"101280601\"));\nhotCities.add(new HotCity(\"杭州\", \"浙江\", \"101210101\"));\n......\n\nCityPicker.from(activity) //activity或者fragment\n  .enableAnimation(true)\t//启用动画效果，默认无\n  .setAnimationStyle(anim)\t//自定义动画\n  .setLocatedCity(new LocatedCity(\"杭州\", \"浙江\", \"101210101\")))  //APP自身已定位的城市，传null会自动定位（默认）\n  .setHotCities(hotCities)\t//指定热门城市\n  .setOnPickListener(new OnPickListener() {\n    @Override\n    public void onPick(int position, City data) {\n      Toast.makeText(getApplicationContext(), data.getName(), Toast.LENGTH_SHORT).show();\n    }\n      \n    @Override\n    public void onCancel(){\n      Toast.makeText(getApplicationContext(), \"取消选择\", Toast.LENGTH_SHORT).show();     \n    }\n      \n    @Override\n    public void onLocate() {\n      //定位接口，需要APP自身实现，这里模拟一下定位\n      new Handler().postDelayed(new Runnable() {\n        @Override\n        public void run() {\n          //定位完成之后更新数据\n          CityPicker.getInstance()\n            .locateComplete(new LocatedCity(\"深圳\", \"广东\", \"101280601\"), LocateState.SUCCESS);\n        }\n      }, 3000);\n    }\n  })\n  .show();\n```\n\n### 关于自定义主题：\n\n在`style.xml` 中自定义主题并且继承`DefaultCityPickerTheme` ，别忘了在`manifest.xml` 设置给`activity`。\n\n```xml\n\u003cstyle name=\"CustomTheme\" parent=\"DefaultCityPickerTheme\"\u003e\n        \u003citem name=\"cpCancelTextColor\"\u003e@color/color_green\u003c/item\u003e\n        \u003citem name=\"cpSearchCursorDrawable\"\u003e@color/color_green\u003c/item\u003e\n        \u003citem name=\"cpIndexBarNormalTextColor\"\u003e@color/color_green\u003c/item\u003e\n        \u003citem name=\"cpIndexBarSelectedTextColor\"\u003e@color/color_green\u003c/item\u003e\n        \u003citem name=\"cpSectionHeight\"\u003e@dimen/custom_section_height\u003c/item\u003e\n        \u003citem name=\"cpOverlayBackground\"\u003e@color/color_green\u003c/item\u003e\n  \t\t......\n\u003c/style\u003e\n```\n\n`CityPicker` 中自定义的所有属性如下，有些属性值必须是引用类型`refrence`，使用时注意。\n\n```xml\n\u003cresources\u003e\n    \u003cattr name=\"cpCancelTextSize\" format=\"dimension|reference\" /\u003e\n    \u003cattr name=\"cpCancelTextColor\" format=\"color|reference\" /\u003e\n\n    \u003cattr name=\"cpClearTextIcon\" format=\"reference\" /\u003e\n    \u003cattr name=\"cpSearchTextSize\" format=\"dimension|reference\" /\u003e\n    \u003cattr name=\"cpSearchTextColor\" format=\"color|reference\" /\u003e\n    \u003cattr name=\"cpSearchHintText\" format=\"string|reference\" /\u003e\n    \u003cattr name=\"cpSearchHintTextColor\" format=\"color|reference\" /\u003e\n    \u003cattr name=\"cpSearchCursorDrawable\" format=\"reference\" /\u003e\n\n    \u003cattr name=\"cpListItemTextSize\" format=\"dimension|reference\" /\u003e\n    \u003cattr name=\"cpListItemTextColor\" format=\"color|reference\" /\u003e\n    \u003cattr name=\"cpListItemHeight\" format=\"dimension|reference\"/\u003e\n\n    \u003cattr name=\"cpEmptyIcon\" format=\"reference\"/\u003e\n    \u003cattr name=\"cpEmptyIconWidth\" format=\"dimension|reference\"/\u003e\n    \u003cattr name=\"cpEmptyIconHeight\" format=\"dimension|reference\"/\u003e\n    \u003cattr name=\"cpEmptyText\" format=\"string|reference\"/\u003e\n    \u003cattr name=\"cpEmptyTextSize\" format=\"dimension|reference\"/\u003e\n    \u003cattr name=\"cpEmptyTextColor\" format=\"color|reference\"/\u003e\n\n    \u003cattr name=\"cpGridItemBackground\" format=\"color|reference\"/\u003e\n    \u003cattr name=\"cpGridItemSpace\" format=\"reference\"/\u003e\n\t\u003c!--悬浮栏--\u003e\n    \u003cattr name=\"cpSectionHeight\" format=\"reference\"/\u003e\n    \u003cattr name=\"cpSectionTextSize\" format=\"reference\" /\u003e\n    \u003cattr name=\"cpSectionTextColor\" format=\"reference\" /\u003e\n    \u003cattr name=\"cpSectionBackground\" format=\"reference\" /\u003e\n\n    \u003cattr name=\"cpIndexBarTextSize\" format=\"reference\" /\u003e\n    \u003cattr name=\"cpIndexBarNormalTextColor\" format=\"reference\" /\u003e\n    \u003cattr name=\"cpIndexBarSelectedTextColor\" format=\"reference\" /\u003e\n\t\u003c!--特写布局--\u003e\n    \u003cattr name=\"cpOverlayWidth\" format=\"dimension|reference\"/\u003e\n    \u003cattr name=\"cpOverlayHeight\" format=\"dimension|reference\"/\u003e\n    \u003cattr name=\"cpOverlayTextSize\" format=\"dimension|reference\"/\u003e\n    \u003cattr name=\"cpOverlayTextColor\" format=\"color|reference\"/\u003e\n    \u003cattr name=\"cpOverlayBackground\" format=\"color|reference\"/\u003e\n\u003c/resources\u003e\n```\n\nOK，enjoy it~\n\n# Changelog \n\n#### v2.1.0\n\n- 迁移至AndroidX\n\n#### v2.0.3\n\n-   修复状态栏变黑问题\n-   修复字母索引栏被软遮挡的问题\n-   新增取消选择监听\n-   方法调用方式稍微改变\n\n#### v2.0.2\n\n-   修复定位城市偶尔不刷新的bug\n\n#### v2.0.1\n\n-   新增定位接口\n-   修改返回类型为`City` ，可获取城市名、code等数据\n\n#### v2.0.0\n\n-   项目重构优化，结构更清晰\n-   使用RecyclerView\n\n# 感谢\n\n[ImmersionBar](https://github.com/gyf-dev/ImmersionBar)\n\n# About me\n\n掘金：[ https://juejin.im/user/56f3dfe8efa6310055ac719f ](https://juejin.im/user/56f3dfe8efa6310055ac719f)\n\n简书：[ https://www.jianshu.com/u/913a8bb93d12 ](https://www.jianshu.com/u/913a8bb93d12)\n\n淘宝店：[ LEON家居生活馆 （动漫摆件）]( https://shop238932691.taobao.com)\n\n![LEON](https://raw.githubusercontent.com/zaaach/imgbed/master/arts/leon_shop_qrcode.png)\n\n:wink:淘宝店求个关注:wink:\n# QQ群\n\n有兴趣可以加入QQ群一起交流：\n![扫码入群601783167](https://raw.githubusercontent.com/zaaach/imgbed/master/arts/qqgroup.jpg)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaaach%2FCityPicker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzaaach%2FCityPicker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaaach%2FCityPicker/lists"}