Giter Club home page Giter Club logo

fjdropdownmenu's Introduction

下拉筛选菜单

栗子配图.png


栗子惯例,先上GIF

1222.gif


使用姿势

引入

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    compile 'com.github.FJ917:FJDropDownMenu:v1.1'
}

使用

更新v1.1版本

新增适配Fragment,使用区别在于,初始化的方法

DropdownUtils.initFragment(getActivity(),this,view, mask);
ViewUtils.injectFragmentViews(this,view, mask);

结构:由DropdownButton和DropdownColumnView构成

<fj.dropdownmenu.lib.view.DropdownButton
        android:layout_height="match_parent"
        android:layout_weight="match_parent" />
<fj.dropdownmenu.lib.view.DropdownColumnView
        app:columnType="singleRow"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

自定义属性attrs.xml

DropdownButton属性

属性 说明
isLine 是否显示横线
selectedTextColor 选中文字颜色
selectedIcon 选中图标
lineColor 选中横线颜色
notSelectedTextColor 未选中文字颜色
notSelectedIcon 未选中图标

DropdownColumnView属性

属性 说明
columnSelectedIcon 列选中图标
columnType singleRow(单列),doubleRow(双列),threeRow(三列),randomView(任意布局)

在java 代码中需要对DropdownButton和DropdownColumnView加上注解@ViewInject()

@ViewInject(R.id.btnRandomView)
DropdownButton btnRandomView;

@ViewInject(R.id.dcRandomView)
DropdownColumnView dcRandomView;

初始化

DropdownUtils.init(this, mask);
ViewUtils.injectViews(this, mask);

设置数据

//单列
lvType.setSingleRow(this)
        .setSingleRowList(DataBean.getType(), -1)  //单列数据
        .setButton(btnType) //按钮
        .show();
//双列
lvAnimal.setDoubleRow(this)
        .setSingleRowList(DataBean.getAnimalSingle(), -1)//单列数据
        .setDoubleRowList(DataBean.getAnimalDouble(), -1)//双列数据
        .setButton(btnAnimal)          //按钮
        .show();
//三列
lvRegion.setThreeRow(this)
        .setSingleRowList(DataBean.getRegionProvince(), -1)  //单列数据
        .setDoubleRowList(DataBean.getRegionCity(), -1)//双列数据
        .setThreeRowList(DataBean.getRegionArea(), -1)//三列数据
        .setButton(btnRegion) //按钮
        .show();

点击事件接口

implements DropdownI.SingleRow, DropdownI.DoubleRow,DropdownI.ThreeRow
/**
 * 单列表返回
 */
@Override
public void onSingleChanged(DropdownItemObject singleRowObject) {
    Log.d("类型",singleRowObject.getValue());
}
/**
 * 双列表返回
 */
@Override
public void onDoubleSingleChanged(DropdownItemObject singleRowObject) {
    Log.d("动物",singleRowObject.getValue());
}
@Override
public void onDoubleChanged(DropdownItemObject doubleRowObject) {
    Log.d("动物子类",doubleRowObject.getValue());
}
/**
 * 三列表返回
 */
@Override
public void onThreeSingleChanged(DropdownItemObject singleRowObject) {
    Log.d("省",singleRowObject.getValue());
}
@Override
public void onThreeDoubleChanged(DropdownItemObject doubleRowObject) {
    Log.d("市",doubleRowObject.getValue());
}
@Override
public void onThreeChanged(DropdownItemObject threeRowObject) {
    Log.d("区",threeRowObject.getValue());
}

任意布局

btnRandomView.setText("弹出自定义布局");
dcRandomView.setRandom(this)
        .setRandomView(R.layout.random_view)
        .setButton(btnRandomView) //按钮
        .show();

布局返回接口

implements DropdownI.RandomView
@Override
public void onRandom(View view) {
    Button btnRandom = (Button) view.findViewById(R.id.btnRandom);
    final EditText etRandom = (EditText) view.findViewById(R.id.etRandom);
    btnRandom.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(RandomViewActivity.this, etRandom.getText().toString(), Toast.LENGTH_SHORT).show();
            DropdownUtils.hide();//点击后是否收起布局
        }
    });
}

个人博客:WWW.FJ917.COM
简书:www.jianshu.com/u/3d2770e6e489

欢迎加入QQ交流群657206000点我加入
QQ交流群:657206000

fjdropdownmenu's People

Contributors

fj917 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.