3

In version 23 of AppCompat it has been introduced a fade in/out animation for the ActionMode, but I need to disable it.

Motivation: I change the background color of a TabLayout and I am not able to reproduce the very same fading animation, so it looks strange. I tried with ObjectAnimator, but it is not a proper "alpha" effect as in the new AppCompat v23.

According to here appcompat-v7 v23.0.0 statusbar color black when in ActionMode (answer from Mattia) it seems the animation is created from Java (thus not possible to overwrite the xml in the "anim" folder):

mFadeAnim = ViewCompat.animate(mActionModeView).alpha(0f);

Any idea on how to disable the new ActionMode animation?

Reproducing the very same effect between two colors would be also an alternative for me but, as explained before, it does not feel the same...

Thanks, Andrea

Community
  • 1
  • 1
agirardello
  • 2,895
  • 22
  • 22

4 Answers4

4

I had the same problem. I solved it this way:

1) Showing actionmode: I don't disable fadein animation: I just set color of actionbar to the same color as actionmode.

2) Hiding actionmode: For disabling fadingout I just make this call in onDestroyActionMode:

findViewById(R.id.action_mode_bar).setVisibility(View.INVISIBLE);

Don't forget to set previous color to actionbar after that.

wilddev
  • 1,904
  • 2
  • 27
  • 45
1

I also found this issue and I want to propose another solution: Trying to animate the TabLayout background color change, in sync with the ActionMode.

    int colorFrom;
    int colorTo;

    TypedValue colorPrimaryTypedValue = new TypedValue();
    TypedValue actionModeBackgroundTypedValue = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.colorPrimary, colorPrimaryTypedValue, true);
    getActivity().getTheme().resolveAttribute(R.attr.actionModeBackground, actionModeBackgroundTypedValue, true);

    if (actionModeVisible) {
        colorFrom = colorPrimaryTypedValue.data;
        colorTo = actionModeBackgroundTypedValue.data;
    } else {
        colorFrom = actionModeBackgroundTypedValue.data;
        colorTo = colorPrimaryTypedValue.data;
    }


    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
    colorAnimation.setDuration(350); // milliseconds
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            mTabLayout.setBackgroundColor((int) animator.getAnimatedValue());
        }

    });
    colorAnimation.start();

Hope this will help others!

Aalecs
  • 21
  • 1
0

Solution for custom view.

@Override
public void onDestroyActionMode(ActionMode mode) {
   ((View) mode.getCustomView().getParent()).setVisibility(View.INVISIBLE);
}

When you start the action mode you have to pass a callback implementation to it. One of the methods of this callback is onDestroyActionMode. In this method you will receive the instance of the ActionMode. With this you can access the custom view that you've set on it and hide its parent container.

Artenes Nogueira
  • 1,422
  • 1
  • 14
  • 23
0

To show the Contextual Action Bar (CAB) without animation, after startSupportActionMode is called, add:

ViewCompat.animate(mode?.customView?.parent as View).alpha(0f)

To hide the CAB without animation:

override fun onDestroyActionMode(mode: ActionMode?) {
    (mode?.customView?.parent as View).visibility = View.GONE
}

This requires to use a customView for the CAB instead of using a menu.

Zain
  • 37,492
  • 7
  • 60
  • 84