PupopWindow动态获取显示的位置,并添加指示箭头
效果图
项目地址:(欢迎star)
使用方法
mLucklyPopopWindow = new LucklyPopopWindow(this);
//给popupWindow添加数据
mLucklyPopopWindow.setData(getResources().getStringArray(R.array.popupArray), new int[]{R.mipmap.add, R.mipmap.delete, R.mipmap.modify, R.mipmap.update});
mAdapter.setOnItemClickListener(new RecyclerAdapter.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
//必须设置宽度
mLucklyPopopWindow.setWidth(150);
//监听事件
mLucklyPopopWindow.setOnItemClickListener(new LucklyPopopWindow.OnItemClickListener() {
@Override
public void onItemClick(int position) {
Toast.makeText(MainActivity.this, "点击的位置" + position, Toast.LENGTH_SHORT).show();
mLucklyPopopWindow.dismiss();
}
});
//添加分割线(可选)
mLucklyPopopWindow.addItemDecoration(LucklyPopopWindow.VERTICAL,Color.GRAY,1);
//设置image不显示(可选)
// mLucklyPopopWindow.setImageDisable(true);
//设置image的大小(可选)
mLucklyPopopWindow.setImageSize(20,20);
//显示popopWindow
mLucklyPopopWindow.show(getWindow().getDecorView(), view);
}
});