I'll answer myself, after doing some research. You need two things:
1 - Create a "transparent" activity by setting the following theme in AndroidManifest. If you don't do this, a blank screen will appear:
<style name="TransparentActivity" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
2. Create a TranslationAnimation (or the animation you want) manually, applying it to the root decorView, as well as disable the custom animations by setting them to 0:
overridePendingTransition(0, 0);
// Custom transition
TranslateAnimation translateAnimation = new TranslateAnimation(-translationLength, 0, 0, 0);
translateAnimation.setDuration(350);
translateAnimation.setFillAfter(true);
View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
rootView.startAnimation(translateAnimation);
rootView.getLayoutParams().width = translationLength;
If you want the reverse animation onBackPressed or when your activity finishes:
@Override
public void finish() {
overridePendingTransition(0, 0);
TranslateAnimation translateAnimation = new TranslateAnimation(0, -translationLength, 0, 0);
translateAnimation.setDuration(350);
translateAnimation.setFillAfter(true);
translateAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
YourActivity.super.finish();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
getWindow().getDecorView().findViewById(android.R.id.content).startAnimation(translateAnimation);
}