Skip to content

a nice city picker library like meituan app for Android

Notifications You must be signed in to change notification settings

zhangjm404/CityPicker

 
 

Repository files navigation

CityPicker

Platform API

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

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

Gif

image

Install

Gradle:

compile 'com.github.zhangjm404:CityPicker:1.0.1'

or 下载library手动导入.

Usage

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

step1:

还需要添加CityPickerActivity

<activity
            android:name="com.zaaach.citypicker.CityPickerActivity"
            android:theme="@style/CityPicker.NoActionBar"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden|adjustPan"/>

Step2

写法1: 用ActivityForResult 接收返回的值

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

写法2: 用ActivityForResult 接收返回的值

//启动
Intent intent = new Intent(MainActivity.this, CityPickerActivity.class);
intent.putExtra(CityPickerActivity.KEY_EVENTBUS_TAG, TAG_MAIN);
intent.putExtra(CityPickerActivity.KEY_LOCATE_CITY, "广州");
startActivity(intent);

//接收
@Subscriber(tag = TAG_MAIN, mode = ThreadMode.MAIN)
private void getCity(MsgEventBus msgEventBus) {
    resultTV.setText("当前选择:" + msgEventBus.getCity());
}

Step3:

enjoy it.

Proguard

注意混淆

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

Ad

原作者的动漫周边淘宝店 ,希望亲可以关注下(dan):

二维码

自定义标题栏

step1:

新建一个 Activity 继承 CityPickerActivity

step2:

重写 customTitleLayout 方法

@Override
    public void customTitleLayout(LinearLayout layoutTitle) {
        super.customTitleLayout(layoutTitle);
        layoutTitle.removeAllViews();
        TextView textView = new TextView(this);
        textView.setText("自定义标题栏");
        textView.setBackgroundColor(Color.RED);
        layoutTitle.addView(textView);
    }

step3:

按照上面的方法,跳到自定义的 Activity 即可

About

a nice city picker library like meituan app for Android

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%