上下文操作栏 - 在现有操作栏上方添加的操作栏(两个操作栏)

Contextual Action Bar - action bar added above existing action bar (two action bars)

我有一个 RecyclerView,它包含多个 CardView,当用户 长时间点击 时,一个 CardView,一个上下文操作栏显示有 "delete" 选项。

我使用 recyclerview-multiselect 库来完成此操作,并按照教程进行操作。

视频适配器:

public class VideosAdapter extends RecyclerView.Adapter<VideosAdapter.MyViewHolder> {

    private Context context;
    private List<VideoItem> videoList;
    private ModalMultiSelectorCallback mActionModeCallback;
    private MultiSelector mMultiSelector;

    public VideosAdapter(Context context, List<VideoItem> videoList, ModalMultiSelectorCallback mActionModeCallback, MultiSelector mMultiSelector) {
        this.context = context;
        this.videoList = videoList;
        this.mActionModeCallback = mActionModeCallback;
        this.mMultiSelector = mMultiSelector;
    }


    public class MyViewHolder extends SwappingHolder
            implements View.OnLongClickListener, View.OnClickListener {
        public ImageView thumbnail;
        private MultiSelector mMultiSelector;

        public MyViewHolder(View itemView, MultiSelector mMultiSelector) {
            super(itemView, mMultiSelector);
            this.mMultiSelector = mMultiSelector;
            itemView.setLongClickable(true);
            thumbnail = (ImageView) itemView.findViewById(R.id.thumbnail);
            setSelectionModeBackgroundDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.background_activated, null));
            thumbnail.setOnLongClickListener(this);
            thumbnail.setOnClickListener(this);
        }


        @Override
        public boolean onLongClick(View view) {
            if (!mMultiSelector.isSelectable()) {
                ((AppCompatActivity) context).startSupportActionMode(mActionModeCallback);
                mMultiSelector.setSelectable(true);
                mMultiSelector.setSelected(MyViewHolder.this, true);
                return true;
            }
            return false;
        }

        @Override
        public void onClick(View view) {
            if (mMultiSelector.tapSelection(this)) {
                // Selection is on, so tapSelection() toggled item selection.
            } else {
                // Selection is off; handle normal item click here.
            }
        }
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.video_card, parent, false);

        return new MyViewHolder(itemView, mMultiSelector);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        VideoItem video = videoList.get(position);
        // loading album cover using Glide library
        Glide.with(context).load(video.getThumbnail()).into(holder.thumbnail);
    }


    @Override
    public int getItemCount() {
        return videoList.size();
    }
}

GalleryFragment:

public class GalleryFragment extends Fragment {

    private RecyclerView recyclerView;
    private VideosAdapter adapter;
    private List<VideoItem> videoList;

    private MultiSelector mMultiSelector = new MultiSelector();
    private ModalMultiSelectorCallback mActionModeCallback
            = new ModalMultiSelectorCallback(mMultiSelector) {

        @Override
        public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
            super.onCreateActionMode(actionMode, menu);
            getActivity().getMenuInflater().inflate(R.menu.toolbar_delete_manu, menu);
            return true;
        }

        @Override
        public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
            if (menuItem.getItemId() == R.id.toolbar_item_delete) {
                actionMode.finish();

                for (int i = videoList.size(); i >= 0; i--) {
                    if (mMultiSelector.isSelected(i, 0)) {
                        // remove item from list
                        recyclerView.getAdapter().notifyItemRemoved(i);
                    }
                }

                mMultiSelector.clearSelections();
                return true;

            }
            return false;
        }
    };



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_gallery, container, false);

        recyclerView = (RecyclerView) root.findViewById(R.id.recycler_view);

        videoList = new ArrayList<>();
        adapter = new VideosAdapter(getActivity(), videoList, mActionModeCallback, mMultiSelector);

        recyclerView.setAdapter(adapter);

        prepareVideos(); // getting videos objects for the adapter
        return root;
    }
}

我遇到的问题是 - 当我 select 一个 CardView 时, new menu/toolbar (toolbar_delete_manu.xml) 显示为 current over/instead menu/toolbar.

实际上发生的事情是这样的:

上下文工具栏覆盖现有工具栏。

我该如何解决?我希望它 而不是

只需将 <item name="android:windowActionModeOverlay">true</item> 添加到您的 AppTheme/Style