1

BottomAppBar widget from support library in com.android.support package has isFabAttached flag and method. In 28.0.0-alpha1 version it has public access. But after release of stable version 28.0.0 it is not available any more.

I used bottomAppBar.isFabAttached = false for animated detach and bottomAppBar.isFabAttached = true for vertical attach animations. But after update to com.android.support:design:28.0.0 isFabAttached has private access and as result animation doesn't work. Only horizontal animation is available for now.

How to animate fab button like on this picture for last release version of com.android.support:design:28.0.0 library?

enter image description here


UPDATE: the issue resolved, I have copied the code from BottomAppBar and created a custom view: CustomBottomAppBar in the android.support.design.bottomappbar package and added next code:

public void setFabAttached(boolean attached) {
    maybeAnimateAttachChange(attached);
    maybeAnimateMenuView(fabAlignmentMode, attached);
    this.fabAttached = attached;
}

private void maybeAnimateAttachChange(boolean targetAttached) {
    if (fabAttached == targetAttached || !ViewCompat.isLaidOut(this)) {
        return;
    }

    if (attachAnimator != null) {
        attachAnimator.cancel();
    }

    List<Animator> animators = new ArrayList<>();

    createCradleShapeAnimation(targetAttached, animators);
    createFabTranslationYAnimation(targetAttached, animators);

    AnimatorSet set = new AnimatorSet();
    set.playTogether(animators);
    attachAnimator = set;
    attachAnimator.addListener(
            new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    attachAnimator = null;
                }
            });
    attachAnimator.start();
}
Prilaga
  • 818
  • 10
  • 18
  • Have you tried using reflection to access that field? – Nick Mowen Oct 31 '18 at 01:41
  • @NickMowen Thanks for the answer! No, didn't try the reflection. But I copied 2 classes: BottomAppBar and BottomAppBarTopEdgeTreatment and modified them. I hoped that there is a way to use default BottomAppBar. – Prilaga Oct 31 '18 at 07:16

0 Answers0