在主题中使用默认动画
本文关键字:默认 动画 | 更新日期: 2023-09-27 18:28:37
在Styles.xml
:中编写主题时,如何访问活动的一些内置动画,如FadeIn
或FadeOut
<style name="Theme.Splash" parent="android:Theme">
<item name="android:windowBackground">@drawable/Splash_mid</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowEnterAnimation"> ??? </item>
<item name="android:windowExitAnimaiton"> ??? </item>
</style>
基本上,我希望我的启动屏幕淡出,而主菜单淡入。
编辑:
[Activity(Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Thread.Sleep(1000);
Intent intent = new Intent(this, typeof(MenuActivity));
StartActivity(intent);
OverridePendingTransition(Android.Resource.Animation.SlideInLeft,
Android.Resource.Animation.SlideOutRight);
}
}
MenuActivity只是立即弹出,而不是动画
编辑2:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="map_split.map_split"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto"
android:theme="@style/Theme.Splash" > (...user permissions...) </manifest>
您可以使用安卓SDK提供的默认fade_in和fade_out动画,如下所示:
<style name="Theme.Splash" parent="android:Theme">
<item name="android:windowBackground">@drawable/splash_mid</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">@style/DefaultAnimation</item>
</style>
<style name="DefaultAnimation">
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
</style>
这些文件如下所示:
fade_in:
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@interpolator/decelerate_quad"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="@android:integer/config_longAnimTime" />
淡出:
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@interpolator/accelerate_quad"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="@android:integer/config_mediumAnimTime" />
编辑:
如评论中所述:
OverridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);