Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent toolbar and navigation bar blinking during shared view activity transition?

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- enable window content transitions -->
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowActionBarOverlay">false</item>
    <item name="android:windowSharedElementsUseOverlay">false</item>

</style>

or excluding from java class navigation and statusbar from transition

    View decor = ((PhotosActivity)context).getWindow().getDecorView();
    View statusBar = decor.findViewById(android.R.id.statusBarBackground);
    View navBar = decor.findViewById(android.R.id.navigationBarBackground);


    ActivityOptionsCompat options = ActivityOptionsCompat.
            makeSceneTransitionAnimation((PhotosActivity) context,
                    new  android.support.v4.util.Pair<>(photo, "photo")
                    new android.support.v4.util.Pair<>(statusBar, Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME),
                    new android.support.v4.util.Pair<>(navBar, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME));
            );
    context.startActivity(photoIntent, options.toBundle());

it continues blinking

like image 686
I.S Avatar asked Jul 04 '16 06:07

I.S


1 Answers

View decor = getWindow().getDecorView(); this decor view used to get the default action bar.

makeSceneTransitionAnimation used to define the shared widgets between the two activities.

To prevent flickering for action bar, status bar and navigation bar. Please add these lines of code in the onCreate method for the 2 Activities:

Fade fade = new Fade();
View decor = getWindow().getDecorView();
fade.excludeTarget(decor.findViewById(R.id.action_bar_container), true);
fade.excludeTarget(android.R.id.statusBarBackground, true);
fade.excludeTarget(android.R.id.navigationBarBackground, true);

getWindow().setEnterTransition(fade);
getWindow().setExitTransition(fade);
like image 185
O-BL Avatar answered Sep 22 '22 08:09

O-BL