现在使用比较多的类似美团等APP的城市选择界面.
2步即可实现,就是这么简单粗暴!
下载demo.apk体验.
Gradle: Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.YLBFDEV:CityPicker:1.2'
}
Maven: Step 1. Add the repositories
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Step 2. Add the dependency
<dependency>
<groupId>com.github.YLBFDEV</groupId>
<artifactId>CityPicker</artifactId>
<version>1.2</version>
</dependency>
- *** Old Version *** Gradle:
compile 'com.zaaach:citypicker:1.1'
or Maven:
<dependency>
<groupId>com.zaaach</groupId>
<artifactId>citypicker</artifactId>
<version>1.1</version>
<type>pom</type>
</dependency>
or 下载library手动导入.
CityPicker
本身已经引入了高德地图定位sdk.
在你项目的manifest.xml
中添加开发平台申请的key
<meta-data android:name="com.amap.api.v2.apikey"
android:value="your key"/>
还需要添加CityPickerActivity
<activity
android:name="com.zaaach.citypicker.CityPickerActivity"
android:theme="@style/CityPicker.NoActionBar"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustPan"/>
private static final int REQUEST_CODE_PICK_CITY = 0;
//启动
startActivityForResult(new Intent(MainActivity.this, CityPickerActivity.class),
REQUEST_CODE_PICK_CITY);
//重写onActivityResult方法
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PICK_CITY && resultCode == RESULT_OK){
if (data != null){
String city = data.getStringExtra(CityPickerActivity.KEY_PICKED_CITY);
resultTV.setText("当前选择:" + city);
}
}
}
enjoy it.
注意混淆
//定位
-keep class com.amap.api.location.**{*;}
-keep class com.amap.api.fence.**{*;}
-keep class com.autonavi.aps.amapapi.model.**{*;}