BottomAppBar 小部件具有 isFabAttached 标志和方法。在 28.0.0-alpha1 版本中,它具有公共访问权限。但是发布稳定版本 28.0.0 后,该版本不再可用。
我使用bottomAppBar.isFabAttached = false
进行动画分离,使用bottomAppBar.isFabAttached = true
进行垂直附加动画。但是在更新到com.android.support:design:28.0.0之后,isFabAttached
具有私有访问权限,因此动画无法正常工作。目前仅提供水平动画。
如何为com.android.support:design:28.0.0
库的最后发行版制作如上图所示的fab按钮?
更新:问题已解决,我已经从BottomAppBar复制了代码,并在 android.support.design.bottomappbar <中创建了一个自定义视图: CustomBottomAppBar / strong>包并添加了下一个代码:
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();
}