一款仿iOS长按菜单弹窗的自定义控件。
implementation 'com.ryan.github:menupopupview:1.0.0'
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);
}
}
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);
// 显示在anchor底部
popupView.setPopupLocation(PopupLayout.PopupLocation.Bottom);
// 显示在anchor顶部
popupView.setPopupLocation(PopupLayout.PopupLocation.TOP);
// 显示PopupView
popupView.show(v);
adapter.notifyDataSetChanged();
// 设置item的分割线颜色
popupView.setDriverColorResId(int colorResId);
// 设置左右指示器的分割线颜色
popupView.setIndicatorDriverColorResId(int colorResId);