FJDropDownMenu

Project Url: FJ917/FJDropDownMenu
Introduction: 下拉筛选菜单
More: Author   ReportBugs   
Tags:
菜单-

栗子配图.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
Apps
About Me
GitHub: Trinea
Facebook: Dev Tools