To fade out current activity:
Create a style in res/values:
<style name="PageTransition.Activity" parent="@android:style/Animation.Activity">
<item name="android:activityOpenEnterAnimation">@android:anim/fade_in</item>
<item name="android:activityOpenExitAnimation">@android:anim/fade_out</item>
<item name="android:activityCloseEnterAnimation">@android:anim/fade_out</item>
<item name="android:activityCloseExitAnimation">@android:anim/fade_in</item>
</style>
Then in your activiy's style which is usually Apptheme for MainActivity:
add this line :
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/one</item>
<item name="colorPrimaryDark">@color/one</item>
<item name="colorAccent">@color/colorAccent</item>
name="android:windowAnimationStyle">@style/PageTransition.Activity</item>
</style>
To start next activity's UI delayed:
For your case, you'll need to use handler to delay transitions:
private final int interval = 1000; // 1 Second
private Handler handler = new Handler();
private Runnable runnable = new Runnable() {
public void run() {
ValueAnimator animator1 = ValueAnimator.ofInt(10, 0);
animator1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float x = (Integer) valueAnimator.getAnimatedValue() / (float) 10;
yourview.setAlpha(x);
}
});
animator1.setDuration(500);
animator1.start();
}
Call this oncreate:
handler.postAtTime(runnable, System.currentTimeMillis() + interval);
handler.postDelayed(runnable, 2000); //two seconds
Obviously, you wanna set your initial alphas to 0.
Hope this helped!
EDIT:
Define your own fadein-fadeout anims if your want to customize duration...
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/decelerate_quad"
android:fromAlpha="startalpha" android:toAlpha="endalpha"
android:duration="{YourDuration in ms}"/>
If the previous way fails for some APIs, use this before starting your activity:
...
overridePendingTransition(int enterAnim, int exitAnim);
startActivity(intent);
....
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…