Android Studio fading splash into main

前端 未结 1 1412
我在风中等你
我在风中等你 2021-02-06 07:59

I currently am working on an android app. Just started and I was able to implement my splash screen. However, I don\'t like the transition between that and the main activity. I

相关标签:
1条回答
  • 2021-02-06 08:31

    You could use two .xml files to fade in a new Activity and fade out the current Activity.

    fade_in.xml

    <?xml version="1.0" encoding="utf-8"?>
    <alpha xmlns:android="http://schemas.android.com/apk/res/android"
           android:interpolator="@android:anim/accelerate_interpolator"
           android:fromAlpha="0.0" android:toAlpha="1.0"
           android:duration="500" />
    

    fade_out.xml

    <?xml version="1.0" encoding="utf-8"?>
    <alpha xmlns:android="http://schemas.android.com/apk/res/android"
           android:interpolator="@android:anim/accelerate_interpolator"
           android:fromAlpha="1.0" android:toAlpha="0.0"
           android:fillAfter="true"
           android:duration="500" />
    

    Use it in code like that: (Inside your Activity)

    Intent intent = new Intent();
            intent.setClass(sPlashScreen, MainActivity.class);
            startActivity(intent);
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    

    The above code will fade out the currently active Activity and fade in the newly started Activity.

    0 讨论(0)
提交回复
热议问题