如何在RecyclerView项目下方显示弹出窗口?

时间:2016-07-19 12:41:15

标签: android android-layout android-recyclerview popupwindow

如何在RecyclerView项目下方显示弹出窗口?

我应该使用PopupWindow,因为菜单是自定义布局

见图:

enter image description here

2 个答案:

答案 0 :(得分:1)

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(inputSource); String xml = doc.getDocumentElement().getTextContent(); 传递showPopUpMenu(View);你想要附加弹出窗口的地方吗?

View

Full Demo

答案 1 :(得分:0)

将此代码放在viewHolder类

btnExpand.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PopupMenu popup = new PopupMenu(btnExpand.getContext(), itemView);

                    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            switch (item.getItemId()) {
                                case R.id.action_Delete:
                                    moveFile(recordName.getText().toString(), getAdapterPosition());
                                    return true;

                                default:
                                    return false;
                            }
                        }
                    });
                    popup.inflate(R.menu.second_contect);
                    popup.setGravity(Gravity.RIGHT);
                    try {
                        Field mFieldPopup=popup.getClass().getDeclaredField("mPopup");
                        mFieldPopup.setAccessible(true);
                        MenuPopupHelper mPopup = (MenuPopupHelper) mFieldPopup.get(popup);
                        mPopup.setForceShowIcon(true);
                    } catch (Exception e) {

                    }
                    popup.show();
                }
            });

你可以看到我的popupmenu

enter image description here