I want my launcher activity to slide in from the right to the left when it is opened or returned to from a previous activity. It currently slides from the right to the left when it switches to another activity, but not when it is opened or the back button is pressed.
Here is the relevant XML for the style that is applied to my launcher activity:
styles.xml
<item name="android:windowContentTransitions">true</item>
<item name="android:windowEnterTransition">@android:transition/slide_left</item>
<item name="android:windowExitTransition">@android:transition/slide_left</item>
<item name="android:windowReenterTransition">@android:transition/slide_right</item>
<item name="android:windowReturnTransition">@android:transition/slide_left</item>
My activity moves to the next activity when a button is clicked. This is my onClickListener:
Button register = (Button)findViewById(R.id.registerBtn);
register.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
Intent i = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(i, ActivityOptions.makeSceneTransitionAnimation(LoginActivity.this).toBundle());
}
});
I believe the ActivityOptions.makeSceneTransitionAnimation method may have something to do with why the exit transition works, but how do I apply this for an enter transition?
If your activity is AppCompatActivity, try this:
Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(LoginActivity.this).toBundle();
ActivityCompat.startActivity(RegisterActivity.this, intent, bundle);
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