如何通过长按进入动作模式时对再循环视图项目实施涟漪效​​应

时间:2016-05-14 18:30:42

标签: android

目前,当我长按回收者视图项时,应用程序将进入操作模式。这就是我实现这种功能的方式。

WatchlistArrayRecyclerViewAdapter.java

@Override
public WatchlistArrayRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                                   int viewType) {
    // create a new view
    final View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.watchlist_row_layout, parent, false);

    v.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int position = recyclerView.getChildAdapterPosition(view);

            if (actionMode) {
                toggleSelection(position);
                v.setActivated(selectedItems.get(position, false));
            }

            recyclerViewOnItemClickListener.onItemClick(view, position);
        }
    });

    v.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int position = recyclerView.getChildAdapterPosition(view);

            if (!actionMode) {
                toggleSelection(position);
                v.setActivated(selectedItems.get(position, false));
            }

            recyclerViewOnItemClickListener.onItemLongPress(view, position);

            return true;
        }
    });

    ViewHolder vh = new ViewHolder(v);
    return vh;
}

WatchlistFragment.java

@Override
public void onItemLongPress(View childView, int position) {
    if (actionMode != null) {
        return;
    }

    actionMode = ((AppCompatActivity)getActivity()).startSupportActionMode(new AnActionModeOfEpicProportions());
    watchlistArrayRecyclerViewAdapter.setActionMode(true);

    updateTitle();
}

watchlist_linear_layout_selector_material_light.xml

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@color/watchlist_row_layout_selected_color_material_light">
    <item android:id="@android:id/mask"
        android:drawable="@android:color/white" />
    <item android:drawable="@drawable/watchlist_linear_layout_selector_for_ripple_material_light"/>
</ripple>

watchlist_linear_layout_selector_for_ripple_material_light.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_activated="true" android:drawable="@drawable/watchlist_row_layout_selected_color_material_light" />

    <item android:state_focused="true" android:drawable="@drawable/watchlist_row_layout_selected_color_material_light" />   <!-- focused -->
    <item android:state_selected="true" android:drawable="@drawable/watchlist_row_layout_selected_color_material_light" />  <!-- selected -->

    <item android:drawable="@drawable/watchlist_row_layout_normal_color_material_light" />
</selector>

这是我长时间按下时的样子。

https://youtu.be/2biPlMwlmkk

然而,当我看到WhatsApp时,我意识到应用程序进入动作模式的那一刻,会有另一个连锁反应。它看起来如下

https://youtu.be/1PuRAv-DfWs

我可以知道,我怎样才能达到这样的效果?

0 个答案:

没有答案