自定义后退按钮动画自定义、按钮、动画

2023-09-05 06:41:53 作者:Outlier(局外人)

默认的动画时,返回按钮是pressed是从左至右滑动。我想替换一个自定义动画。我目前认为的某种组合 onBack pressed() overridePendingTransition 会做的伎俩,但我一直没能得到它的工作。

The default animation when the Back button is pressed is a slide from left to right. I'd like to replace that with a custom animation. I'm currently thinking that some combination of onBackPressed() and overridePendingTransition will do the trick, but I haven't been able to get it working.

推荐答案

我觉得你不应该使用结束(),因为在浏览存储的数据将被删除

I think you shouldn't use finish() because the data stored by the Views will be erased

@Override
public void onBackPressed() {
    super.onBackPressed();
    overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
}