user5699033
user5699033

Reputation:

Using default animation in a theme

How do I access some of the built in animations like FadeIn or FadeOut for activities when writing a theme in Styles.xml:

<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>

Basically, I want my splash screen to fade out and my main menu to fade in.

EDIT:

[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 just pops up instantly instead of animating

EDIT 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>

Upvotes: 0

Views: 411

Answers (1)

Hussein El Feky
Hussein El Feky

Reputation: 6707

You can use the default fade_in and fade_out animation provided by the Android SDK like so:

<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>

These files look like that:

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" />

fade_out:

<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" />

EDIT:

As mentioned in the comments:

OverridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

Upvotes: 1

Related Questions