如何防止共享视图活动过渡期间工具栏和导航栏闪烁?

时间:2016-07-04 06:11:02

标签: android android-activity android-animation

 <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>

或 从转换

中的java类导航和状态栏中排除
    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());

它继续闪烁

1 个答案:

答案 0 :(得分:2)

View decor = getWindow().getDecorView();decor视图用于获取默认操作栏。

makeSceneTransitionAnimation用于定义两个活动之间的共享窗口小部件。

为防止操作栏,状态栏和导航栏闪烁。请为这2个活动在onCreate方法中添加以下代码行:

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);