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