Showing custom View under swiped RecyclerView item

后端 未结 5 1086
独厮守ぢ
独厮守ぢ 2020-12-24 08:55

First of all, I saw this question: Adding a colored background with text/icon under swiped row when using Android's RecyclerView

However, even though the title s

5条回答
  •  梦谈多话
    2020-12-24 09:41

    For people still finding this default, this is the simplest way.

    A simple utility class to add a background, an icon and a label to a RecyclerView item while swiping it left or right.

    insert to Gradle

    implementation 'it.xabaras.android:recyclerview-swipedecorator:1.2.1'
    

    Override onChildDraw method of ItemTouchHelper class

    @Override
    public void onChildDraw (Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,float dX, float dY,int actionState, boolean isCurrentlyActive){
    
        new RecyclerViewSwipeDecorator.Builder(MainActivity.this, c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
                .addBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.my_background))
                .addActionIcon(R.drawable.my_icon)
                .create()
                .decorate();
    
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
    

    for more info -> https://github.com/xabaras/RecyclerViewSwipeDecorator

提交回复
热议问题