增加MenuItem的获取,预设的的个别几项属性设置settter和getter
增加菜单被关闭监听
dependencies {
compile 'com.lrq.menu:addpopmenu:latestVersion'
}
在对应要弹出的按钮事件上加上这段代码
mPopMenu = new PopMenu.Builder().attachToActivity(MainActivity.this)
.addMenuItem(new PopMenuItem("广场", getResources().getDrawable(R.drawable.tabbar_compose_idea)))
.addMenuItem(new PopMenuItem("私密", getResources().getDrawable(R.drawable.tabbar_compose_photo)))
.addMenuItem(new PopMenuItem("家庭圈", getResources().getDrawable(R.drawable.tabbar_compose_headlines)))
.setOnItemClickListener(new PopMenuItemListener() {
@Override
public void onItemClick(PopMenu popMenu, int position) {
Toast.makeText(MainActivity.this, "你点击了第" + position + "个位置", Toast.LENGTH_SHORT).show();
}
})
.build();
mPopMenu.show();
/**
* 关闭按钮距离屏幕底部位置单位dp
*/
private int mCloseMenuMarginbottom=15;
/**
* 背景颜色
*/
private int mBackGroundColor=Color.parseColor("#f0f3f3f3");
/**
* 关闭按钮的图片
*/
private int mCloseButtomResourceid=R.drawable.tabbar_compose_background_icon_close;
/**
* Menu相对于屏幕顶部的距离的的倍数因子(屏幕高度减去菜单本身高度剩下部分除以这个倍数因子)
*/
private float mMarginTopRemainSpace=1.5f;
/**
* 是否错位弹出菜单
*/
private boolean mIsmalpositionAnimatOut=true;
/**
* 错位动画时间(毫秒)默认50
*/
private int malposition=50;
/**
* 一行多少列,默认三列
*
*/
public Builder columnCount(int count) {
this.columnCount = count;
return this;
}
/**
*添加菜单项
*
*/
public Builder addMenuItem(PopMenuItem menuItem) {
this.itemList.add(menuItem);
return this;
}
/**
* 动画执行时间,默认300毫秒
*
*/
public Builder duration(int duration) {
this.duration = duration;
return this;
}
/**
* 拉力系数,默认10
*
*/
public Builder tension(double tension) {
this.tension = tension;
return this;
}
/**
* 摩擦力系数默认5
*
*/
public Builder friction(double friction) {
this.friction = friction;
return this;
}
/**
* item水平之间的间距
*/
public Builder horizontalPadding(int padding) {
this.horizontalPadding = padding;
return this;
}
/**
* item竖直之间的间距
*/
public Builder verticalPadding(int padding) {
this.verticalPadding = padding;
return this;
}
/**
* item点击监听器
*/
public Builder setOnItemClickListener(PopMenuItemListener listener) {
this.popMenuItemListener = listener;
return this;
}