0

Is there a way to animate BottomNavigationBar Icon to be animated when selected?

I tried doing but I get an error saying that:

com.google.android.material.shape.MaterialShapeDrawable cannot be cast to 
android.graphics.drawable.GradientDrawable

I know that It cannot be cast so I am asking is there a way to achieve this??

Here is the code which I tried:

    View m = this.findViewById(R.id.bot_nav_view);
    final GradientDrawable gradient = (GradientDrawable) m.getBackground();

    ValueAnimator animator = TimeAnimator.ofFloat(0.0f, 1.0f);
    animator.setDuration(500);
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.addUpdateListener(valueAnimator -> {

        Float fraction = valueAnimator.getAnimatedFraction();
        //s = orange. m= yellow. e= blue.
        int newStrat = (int) evaluator.evaluate(fraction, start, mid);
        int newMid = (int) evaluator.evaluate(fraction, mid, end);
        int newEnd = (int) evaluator.evaluate(fraction, end, start);
        int[] newArray = {newStrat, newMid, newEnd};
        gradient.setColors(newArray);

    });

Please is there a way

X Vid
  • 1
  • I have tried doing it with GradientDrawable which is always working with any other view but in terms of botNav it seems I am not able to cast it – X Vid Jun 06 '22 at 21:15
  • Please without using ShapeShifter. I am trying to change the color to multiple color when selected – X Vid Jun 06 '22 at 21:15

0 Answers0