[英]How do I set the screen transitions for all screens in Android?
在我的應用程序中,我想使用淡入淡出的動畫在所有屏幕/活動之間切換。 我可以設置一些東西,可能在清單中,允許在任何屏幕/活動之間進行此操作嗎?
-----編輯-----
我根據哈馬德的建議更新了我的文件。 刪除@android:style/Theme.Holo.Light.NoActionBar
導致我丟失了一些元素的樣式,如填充,邊距,背景,重力,文本顏色等。所以我做了以下修復樣式,但現在看來一起運行“跳轉到下一個屏幕”和“淡入下一個屏幕”。
screen_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="1000" >
</alpha>
</set>
screen_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="1000" >
</alpha>
</set>
styles.xml
<style name="ScreenTransition.Activity" parent="@android:style/Theme.Holo.Light.NoActionBar">
<item name="android:windowEnterAnimation">@anim/screen_in</item>
<item name="android:windowExitAnimation">@anim/screen_out</item>
</style>
<style name="ScreenTransition" parent="android:Theme.Translucent">
<item name="android:windowAnimationStyle">@style/ScreenTransition.Activity</item>
</style>
AndroidManifest.xml中
<activity
android:name="com.library.books.MainActivity"
android:label="home"
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustPan"
android:theme="@style/ScreenTransition" >
</activity>
為了這:
1.在res/styles.xml
創建一個<style>
,如下所示:
<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>
2.然后,您可以將樣式應用於主題,在同一文件中:
<style name="YourTheme" parent="android:Theme.Translucent">
...
<item name="android:windowAnimationStyle">@style/YourAnimation.Activity</item>
</style>
3.最后將主題應用於清單中的活動:
<activity
android:name=".YourActivity"
android:theme="@style/YourTheme" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.