So I've got WelcomeActivity -> HomeActivity and closing WelcomeActivity with finish()/supportFinishAfterTransition()
. I want to do either a slideTransition or a fadeTransition (open to other suggestions btw).
I've researched this and as it turns out there are 2+ ways of doing it: either with overridePendingTransition
which uses anim.xml files or with Transitions (from the android docs) which use transition.xml files...
I've tried both and both give me unwanted results:
fade_in.xml:
<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="300" />
fade_out.xml:
<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:zAdjustment="top"
android:duration="300" />
WelcomeActivity: (I've tried having finish before the overridePendingTransaction)
startActivity(Intent(this, HomeActivity::class.java))
overridePendingTransition(R.anim.fade_in, R.anim.fade_out)
finish()
style.xml
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowEnterTransition">@transition/enter_fade</item>
<item name="android:windowExitTransition">@transition/exit_fade</item>
My other questions is which approach should I have? Is Google pushing the transitions over the anims for starting new activities?
What I always do is to start an activity(any way you want, ways are listed here).
I use slide transitions using these two files:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromXDelta="0"
android:toXDelta="-100%p" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromXDelta="100%p"
android:toXDelta="0" />
</set>
Then I start an activity like this(this is java):
startActivity(MainActivity.this, SecondActivity.class);
overridePendingTransition(R.anim.slide_in_right.xml, R.anim.slide_in_left.xml);
finish();
Using this, the activity exits giving way to the new one smoothly from right to left.
For the black screen, set the theme of that activity as translucent in the AndroidManifest.xml
file
android:theme="@android:style/Theme.Translucent"
so your code will be something like this
<activity android:name=".Activity"
android:theme="@android:style/Theme.Translucent" />
Answer for the black screen taken from: https://stackoverflow.com/a/6468734/9819031
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With