php 城市定位选择,城市选择、定位、搜索及右侧字母导航

收藏 0

现在使用较多的类似美团、外卖等APP的城市选择界面,一行代码搞定,就是这么简单粗暴!!!

主要功能:

字母悬浮栏

指定热门城市

自定义动画效果

自定义主题

名称或拼音搜索

返回城市名、code等数据

提供定位接口,解耦定位SDK

Preview

screen.gif

f0167731252538349cd0a7e6d265e469.gif

b0c34851ae08e6732043e6610232c18a.gif

Gradle:

dependencies {

implementation 'com.zaaach:citypicker:2.0.3'//必选

implementation 'com.android.support:recyclerview-v7:27.1.1'//必选

}

or Maven:

com.zaaach

citypicker

2.0.3

pom

or 下载library手动导入.

Usage

CityPicker 基于DialogFragment 实现,已提供定位接口,需要APP自身实现定位。

基本使用:

Step1:

在manifest.xml中给使用CityPicker 的activity添加主题android:theme="@style/DefaultCityPickerTheme"

......

Step2:

注意:热门城市使用HotCity ,定位城市使用LocatedCity

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

关于自定义主题:

在style.xml 中自定义主题并且继承DefaultCityPickerTheme ,别忘了在manifest.xml 设置给activity。

@color/color_green

@color/color_green

@color/color_green

@color/color_green

@dimen/custom_section_height

@color/color_green

......

CityPicker 中自定义的所有属性如下,有些属性值必须是引用类型refrence,使用时注意。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
现在使用较多的类似美团、外卖等APP的城市选择界面,一行代码搞定,就是这么简单粗暴!!!主要功能:字母悬浮栏指定热门城市自定义动画效果自定义主题名称或拼音搜索Preview  APK下载demo.apk体验.InstallGradle:implementation 'com.zaaach:citypicker:2.0.0'or Maven:   com.zaaach   citypicker   2.0.0   pom or 下载library手动导入.UsageCityPicker 继承于DialogFragment ,本身没有定位功能,需要APP自身实现定位。基本使用:Step1:在manifest.xml中给使用CityPicker 的activity添加主题android:theme="@style/DefaultCityPickerTheme"   ...... Step2:new CityPickerBuilder()         .setFragmentManager(getSupportFragmentManager()) //此方法必须调用         .setCurrentCity("杭州") //APP自身已定位城市         .setAnimationStyle(anim)  //自定义动画         .setHotCities(new String[]{"北京", "上海", "广州", "深圳"}) //指定热门城市         .setOnPickListener(new OnPickListener() {               @Override               public void onPick(int position, String data) {                       Toast.makeText(getApplicationContext(), data, Toast.LENGTH_SHORT).show();               }})          .show();关于自定义主题:在style.xml 中自定义主题并且继承DefaultCityPickerTheme ,别忘了在manifest.xml 设置给activity。<style name="CustomTheme" parent="DefaultCityPickerTheme">         @color/color_green         @color/color_green         @color/color_green         @color/color_green         @dimen/custom_section_height         @color/color_green    ...... </style>CityPicker 中自定义的所有属性如下,有些属性值必须是引用类型refrence,使用时注意。                    <attr name="cpS

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值