### Basic CityPicker Dialog Implementation and Configuration Source: https://github.com/zaaach/citypicker/blob/master/README.md Demonstrates how to initialize and show the CityPicker dialog. It covers setting hot cities, a pre-located city, enabling animations, and handling user interactions (city selection, cancellation) and location requests. The `onLocate` callback provides an interface for integrating with your app's own location service. ```java List hotCities = new ArrayList<>(); hotCities.add(new HotCity("北京", "北京", "101010100")); //code为城市代码 hotCities.add(new HotCity("上海", "上海", "101020100")); hotCities.add(new HotCity("广州", "广东", "101280101")); hotCities.add(new HotCity("深圳", "广东", "101280601")); hotCities.add(new HotCity("杭州", "浙江", "101210101")); ...... CityPicker.from(activity) //activity或者fragment .enableAnimation(true) //启用动画效果,默认无 .setAnimationStyle(anim) //自定义动画 .setLocatedCity(new LocatedCity("杭州", "浙江", "101210101"))) //APP自身已定位的城市,传null会自动定位(默认) .setHotCities(hotCities) //指定热门城市 .setOnPickListener(new OnPickListener() { @Override public void onPick(int position, City data) { Toast.makeText(getApplicationContext(), data.getName(), Toast.LENGTH_SHORT).show(); } @Override public void onCancel(){ Toast.makeText(getApplicationContext(), "取消选择", Toast.LENGTH_SHORT).show(); } @Override public void onLocate() { //定位接口,需要APP自身实现,这里模拟一下定位 new Handler().postDelayed(new Runnable() { @Override public void run() { //定位完成之后更新数据 CityPicker.getInstance() .locateComplete(new LocatedCity("深圳", "广东", "101280601"), LocateState.SUCCESS); } }, 3000); } }) .show(); ``` -------------------------------- ### Add JitPack Repository to Project Gradle Source: https://github.com/zaaach/citypicker/blob/master/README.md Configure your project's root `build.gradle` file to include the JitPack Maven repository, which is necessary to resolve the CityPicker library dependency. ```groovy allprojects { repositories { ... maven { url 'https://jitpack.io' } } } ``` -------------------------------- ### Add CityPicker Library Dependency to App Module Source: https://github.com/zaaach/citypicker/blob/master/README.md Include the CityPicker library as an implementation dependency in your app module's `build.gradle` file. Replace `x.y.z` with the latest version from JitPack. ```groovy dependencies { implementation 'com.github.zaaach:CityPicker:x.y.z' } ``` -------------------------------- ### Apply Default CityPicker Theme in AndroidManifest Source: https://github.com/zaaach/citypicker/blob/master/README.md In your `AndroidManifest.xml`, apply the `@style/DefaultCityPickerTheme` to the activity where you intend to use the CityPicker dialog. ```xml ...... ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.