现在使用比较多的类似美团等APP的城市选择界面.

2步即可实现,就是这么简单粗暴!

image

image

下载demo.apk体验.

Gradle:

  1. compile \'com.zaaach:citypicker:1.1\'

or Maven:

  1. <dependency>
  2. <groupId>com.zaaach</groupId>
  3. <artifactId>citypicker</artifactId>
  4. <version>1.1</version>
  5. <type>pom</type>
  6. </dependency>

or 下载library手动导入.

CityPicker本身已经引入了高德地图定位sdk.

在你项目的manifest.xml中添加开发平台申请的key

  1. <meta-data android:name="com.amap.api.v2.apikey"
  2. android:value="your key"/>

还需要添加CityPickerActivity

  1. <activity
  2. android:name="com.zaaach.citypicker.CityPickerActivity"
  3. android:theme="@style/CityPicker.NoActionBar"
  4. android:screenOrientation="portrait"
  5. android:windowSoftInputMode="stateHidden|adjustPan"/>
  1. private static final int REQUEST_CODE_PICK_CITY = 0;
  2. //启动
  3. startActivityForResult(new Intent(MainActivity.this, CityPickerActivity.class),
  4. REQUEST_CODE_PICK_CITY);
  5. //重写onActivityResult方法
  6. @Override
  7. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  8. if (requestCode == REQUEST_CODE_PICK_CITY && resultCode == RESULT_OK){
  9. if (data != null){
  10. String city = data.getStringExtra(CityPickerActivity.KEY_PICKED_CITY);
  11. resultTV.setText("当前选择:" + city);
  12. }
  13. }
  14. }

enjoy it.

注意混淆

  1. //定位
  2. -keep class com.amap.api.location.**{*;}
  3. -keep class com.amap.api.fence.**{*;}
  4. -keep class com.autonavi.aps.amapapi.model.**{*;}

github地址:CityPicker欢迎star~

作者:Bro0cL
链接:https://www.jianshu.com/p/b469c6f02754
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

版权声明:本文为Im-Victor原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/Im-Victor/p/9509456.html