1. 程式人生 > >【Android開源庫】美團等APP城市選擇

【Android開源庫】美團等APP城市選擇

data- pac 就是 blank all ike 需要 高德 city

CityPicker

現在使用比較多的類似美團等APP的城市選擇界面.

2步即可實現,就是這麽簡單粗暴!

Gif

技術分享圖片 image

APK

下載demo.apk體驗.

Install

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手動導入.

Usage

CityPicker本身已經引入了高德地圖定位sdk.

step1:

在你項目的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"/>

Step2

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);
        }
    }
}

Step3:

enjoy it.

Proguard

註意混淆

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

GitHub

github地址:CityPicker歡迎star~



作者:Bro0cL
鏈接:https://www.jianshu.com/p/b469c6f02754
來源:簡書
簡書著作權歸作者所有,任何形式的轉載都請聯系作者獲得授權並註明出處。

【Android開源庫】美團等APP城市選擇