如何在 Android 应用程序中一次更改所有活动转换? [英] How to change all the activity transitions at once in Android application?
问题描述
我知道我可以在 startActivity() 或 finish() 之后立即使用以下代码更改活动转换
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 应用程序中一次更改所有活动转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!