按Home键时禁用windowAnimations

时间:2016-01-20 02:54:28

标签: android android-layout android-fragments android-animation

因此对于我的一个Dialog我正在实现一个滑动动画。它适用于进入和退出。但是,当用户按下主页按钮并且应用程序背景时,windowExitAnimation仍会播放,当返回应用时,windowEnterAnimation也会播放。有没有办法在显示/取消对话框时播放这些动画,而不是在使用主页按钮时播放?

这是我xml的主题

<style name="MyDialogAnimationTheme">
    <item name="android:windowAnimationStyle">@style/MyDialogAnimationTheme.Window</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

<style name="MyDialogAnimationTheme.Window" parent="@android:style/Animation.Activity">
    <item name="android:windowEnterAnimation">@anim/slide_up</item>
    <item name="android:windowExitAnimation">@anim/slide_down</item>
</style>

在代码中,我通过覆盖getTheme()

DialogFragment来设置主题
@Override
public int getTheme() {
    return R.style.MyDialogAnimationTheme;
}

我也尝试过这样设置windowAnimation

myDialog.getWindow().getAttributes().windowAnimations = R.style.MyDialogAnimationTheme_Window;

但同样的问题,动画播放效果很好,但也可以播放应用程序背景的主页按钮。

0 个答案:

没有答案