我有一个带有 FloatingActionButton
的 Activity
。当我按下 FAB 时,会显示一个 AlertDialog
。我想通过使用 Android
的 Material Design
中的显示效果或曲线运动来为其外观设置动画。 documentation只有一个改变现有 View 可见性的例子。
如何为 AlertDialog
实现这一点?
最佳答案
在显示对话框之前,我通过调用对话框的 setOnShowListener
做了类似的事情。我仍然需要完善动画,但这是一个开始:
dialogToAnimate.setOnShowListener(new OnShowListener() {
@Override public void onShow(DialogInterface dialog) {
// Remember that ViewAnimationUtils will not work until API 21.
final View view = dialogToAnimate.getWindow().getDecorView();
final int centerX = view.getWidth() / 2;
final int centerY = view.getHeight() / 2;
// TODO Get startRadius from FAB
// TODO Also translate animate FAB to center of screen?
float startRadius = 20;
float endRadius = view.getHeight();
Animator animator = ViewAnimationUtils.createCircularReveal(view, centerX, centerY, startRadius, endRadius);
animator.setDuration(1000);
animator.start();
}
});
关于android - 如何使用 Material 设计的显示效果在 Android 上显示对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31456559/