Android:覆盖活动主题对话框的待定过渡无效 [英] Android: override pending Transition for Activity Theme Dialog not working

查看:200
本文介绍了Android:覆盖活动主题对话框的待定过渡无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个Android应用程序,需要为自己的活动制作动画。我使用了overridePendingTransition(entr,exit)并在res\anim文件夹中制作了3个xml文件。其中 push_up_in.xml,push_down_out.xml,hold.xml 使用

I have been working on an Android application where I need to make an animation for my activity. I used overridePendingTransition(entr,exit) and made 3 xml files in res\anim folder. which r push_up_in.xml, push_down_out.xml, hold.xml using

<set>
  <translate>
     duration, fromYDelta, toYDelta, zAdjustment
</set>

我为 push_.xmls保留了 zAdjustment = top bottom.xml的底部。一切正常,当我 startactivity(myIntent)和finish()我的活动时,动画在两种情况下都完美无缺。
但是当我将活动主题从 AndroidManifest.xml 文件更改为 Theme.Dialog时,MyActivity.this.finish()上的 overridePendingAnimation 永远不起作用。这意味着我的动画在开始活动时有效,但在完成活动后无效。

I kept zAdjustment=top for push_.xmls and bottom for hold.xml. everything works fine, when I startactivity(myIntent) and finish() my activity the animation works flawless in both cases. BUT when I change my activity theme from AndroidManifest.xml file to "Theme.Dialog" theoverridePendingAnimation on MyActivity.this.finish(); never works. It means my animation works when I start activity but not work when I finish an Activity.

AndroidManifest.xml

<activity
        android:name=".MyActivity"
        android:label="My Activity"
        android:theme="@android:style/Theme.Dialog">
</activity>

如果我简单地删除 Theme语句,一切将再次像魅力一样工作。

If I simply remove the "Theme" statement, everything again start working like a charm.

<activity
        android:name=".MyActivity"
        android:label="My Activity">
</activity>

但我希望我的活动看起来像一个对话框。

but I want my activity to look like a dialog.

推荐答案

这是一个老问题,但这对我有用。我在v4.2.2设备上遇到了这个问题,这是由Dan建议的Theme.Dialog中默认的窗口动画样式引起的。您只需要通过自定义主题就可以摆脱它:

This is an old question, but here's what worked for me. I faced this issue on a v4.2.2 device and it's caused by the default window animation style in Theme.Dialog, as Dan suggested. All you need to do is to simply get rid of it, by customizing your theme:

<style name="CustomTheme" parent="@android:style/Theme.Dialog">
    <item name="android:windowAnimationStyle">@null</item>
    <item name="android:windowEnterAnimation">@null</item>
    <item name="android:windowExitAnimation">@null</item>
    <!-- other customizations -->
</style>

我也将android:windowEnterAnimation和android:windowExitAnimation设置为null,以防万一。现在,您必须在清单中使用自定义主题,并已完成:

I've set android:windowEnterAnimation and android:windowExitAnimation to null as well, just in case. Now you have to use your custom theme in the manifest and you're done:

<activity
    android:name=".MyActivity"
    android:label="My Activity"
    android:theme="@style/CustomTheme">
</activity>

这篇关于Android:覆盖活动主题对话框的待定过渡无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆