如何在Android应用程序改变所有的活动转变为一次? [英] How to change all the activity transitions at once in Android application?
问题描述
我知道startActivity()或结束()
I know I can change activity transition using the following code right after startActivity() or finish()
activity.overridePendingTransition(R.anim.activity_close_enter,R.anim.activity_close_exit);
但是,如果我有我的应用程序十项活动,我必须这样做十次;它是非常难改变。所以,我不知道是否有一种方法来设置应用程序的所有活动转变为一次。有没有在AndroidManifest.xml中任何相应的配置?
But if I have ten activities in my app, I have to do that ten times; and it is quite hard to modify. So I'm wondering if there is a way to set transition for all activities within the application at once. Is there any corresponding configuration in AndroidManifest.xml?
谢谢!
推荐答案
您需要先创建一个<风格>
在RES / styles.xml,就像这样:
You want to first create a <style>
in res/styles.xml, like this:
<style name="YourAnimation.Activity" parent="@android:style/Animation.Activity">
<item name="android:windowEnterAnimation">@anim/your_in_down</item>
<item name="android:windowExitAnimation">@anim/your_out_down</item>
</style>
然后你可以将样式应用到一个主题,在同一个文件:
Then you can apply the style to a theme, in the same file:
<style name="YourTheme" parent="android:Theme.Translucent">
...
<item name="android:windowAnimationStyle">@style/YourAnimation.Activity</item>
</style>
和最终应用的主题,以你的活动清单:
And finally apply the theme to your activities in the manifest:
<activity
android:name=".YourActivity"
android:theme="@style/YourTheme" />
看看这些链接,以供参考:
Look at these links for reference:
- Android Reference - Apply A Theme
- Android Reference - WindowEnterAnimation
这篇关于如何在Android应用程序改变所有的活动转变为一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!