Skip to content Skip to sidebar Skip to footer

How To Achieve Such Long Pressed Ripple Effect

I do have some basic understanding on how to achieve ripple effect for normal press. How to set state_selected in ripple drawable I was wondering, how can I achieve such long press

Solution 1:

That is the default behaviour of the ripple effect itself for material design. You can add this effect using xml or just the simple way by adding as background or foreground of a view ?attr/selectableItemBackground. Remember that to allow it to work it is necessary that the view has an onClickListener setup. Otherwise, the effect will not be visible to you.

Solution 2:

You can calculate the width and height of the view and you can start animation like below code.This code will start animation from the middle.

  button.setOnLongClickListener(newView.OnLongClickListener() {
        @OverridepublicbooleanonLongClick(View v) {
            int finalRadius=(int)Math.hypot(v.getWidth()/2,v.getHeight()/2);
            Animator anim= null;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                anim = ViewAnimationUtils.createCircularReveal(v,v.getWidth()/2,v.getHeight()/2,0,finalRadius);
                anim.setDuration(400);

                anim.start();
            }
            returntrue;
        }
    });

Post a Comment for "How To Achieve Such Long Pressed Ripple Effect"