Git Product home page Git Product logo

menupopupview's Introduction

MenuPopupView

一个仿iOS长按菜单弹窗的自定义控件

效果图

使用说明

Gradle

// project build.gradle
allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://dl.bintray.com/shamschu/maven'
        }
    }
}

compile 'com.sc.framework.component:menupopupview:1.0.2'

1. 自定义MenuPopupAdapter

public class TestPopupAdapter extends MenuPopupAdapter<String> {

    private List<String> mData;

    public TestPopupAdapter(List<String> data) {
        mData = data;
    }

    // 返回Item View视图对象
    @Override
    public View getView(View container, int position) {
        View view = LayoutInflater.from(container.getContext()).inflate(R.layout.test_item, null);
        TextView tv = (TextView) view.findViewById(R.id.label);
        tv.setText(getItem(position));
        return view;
    }

    /**
     * 获取item数
     *
     * @return item数量
     */
    @Override
    public int getItemCount() {
        return mData.size();
    }

    /**
     * 获取position位置的数据对象
     *
     * @param position 位置索引
     * @return 数据对象
     */
    @Override
    public String getItem(int position) {
        return mData.get(position);
    }
}

2. 创建PopupView并指定Adapter

List<String> menus = new ArrayList<>();
menus.add("default");
menus.add("copy");
MenuPopupAdapter<String> adapter = new TestPopupAdapter(menus);
PopupView popupView = new PopupView(this);
popupView.setAdapter(adapter);

3. 设置依附anchor方向并显示

// 显示在anchor底部
popupView.setPopupLocation(PopupLayout.PopupLocation.Bottom);
// 显示在anchor顶部
popupView.setPopupLocation(PopupLayout.PopupLocation.TOP);
// 显示PopupView
popupView.show(v);

4. 动态改变菜单并刷新

adapter.notifyDataSetChanged();

5. 设置分割线颜色

// 设置item的分割线颜色
popupView.setDriverColorResId(int colorResId);
// 设置左右指示器的分割线颜色
popupView.setIndicatorDriverColorResId(int colorResId);

menupopupview's People

Contributors

ryan-shz 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.