移除白色屏幕,幻灯片窗口转换在启动时创建

Joh*_*upe 13 android android-5.0-lollipop

我正在使用黑色背景的活动.同样的活动还有一个工具栏和一个DrawerLayout.此白色屏幕使外观不一致.

打开活动时,如果幻灯片转换速度很慢,则会更加明显.

有什么办法可以删除吗?

在第二个活动上设置输入转换的代码:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = activity.getWindow();

        Slide slide = new Slide();
        slide.setSlideEdge(Gravity.RIGHT);
        slide.excludeTarget(android.R.id.statusBarBackground, true);
        slide.excludeTarget(android.R.id.navigationBarBackground, true);
        window.setEnterTransition(slide);
        window.setExitTransition(slide);
    }
Run Code Online (Sandbox Code Playgroud)

我的风格

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowActivityTransitions">true</item>
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowAllowEnterTransitionOverlap">false</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowSoftInputMode">stateAlwaysHidden|adjustResize</item>
</style>
Run Code Online (Sandbox Code Playgroud)

And*_*ger 21

如何在已启动活动的过渡幻灯片期间修复白屏:

karaokyos答案利用前Lollipop活动过渡.这些转换以整个活动屏幕为目标,并且不提供在转换期间排除部分屏幕的功能.

John Ernest Guadalupe方法利用Lollipop中引入的过渡(Activity&Fragment Transitions).观察到的"白色屏幕"是窗口背景,在转换过程中逐渐消失(有关活动和片段转换的更多信息).我猜您是在布局的根视图中设置活动的"黑色背景"?将窗口背景设置为黑色可以解决您的问题.

编程方式:

window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
Run Code Online (Sandbox Code Playgroud)

主题:

<item name="android:windowBackground">@android:color/black</item>
Run Code Online (Sandbox Code Playgroud)

这是由此产生的转变.

结果过渡

编辑:如何为调用活动提供所需的滑出(左)转换

第一项活动:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Window window = getWindow();
    Slide slide = new Slide();
    slide.setInterpolator(new LinearInterpolator());
    slide.setSlideEdge(Gravity.LEFT);
    slide.excludeTarget(android.R.id.statusBarBackground, true);
    slide.excludeTarget(android.R.id.navigationBarBackground, true);
    window.setExitTransition(slide); // The Transition to use to move Views out of the scene when calling a new Activity.
    window.setReenterTransition(slide); // The Transition to use to move Views into the scene when reentering from a previously-started Activity.
    window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
}
Run Code Online (Sandbox Code Playgroud)

第二项活动:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Window window = getWindow();
    Slide slide = new Slide();
    slide.setInterpolator(new LinearInterpolator());
    slide.setSlideEdge(Gravity.RIGHT);
    slide.excludeTarget(android.R.id.statusBarBackground, true);
    slide.excludeTarget(android.R.id.navigationBarBackground, true);
    window.setEnterTransition(slide); // The Transition to use to move Views into the initial Scene.
    window.setReturnTransition(slide); // The Transition to use to move Views out of the Scene when the Window is preparing to close.
    window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
}
Run Code Online (Sandbox Code Playgroud)

您可以尝试使用不同的插值器来改变转换的速度.

使用LinearInterpolator进行结果转换:

结果转换

如果你想摆脱滑出第一个活动和滑入第二个活动之间的差距你可以设置:

<item name="android:windowAllowEnterTransitionOverlap">true</item>
Run Code Online (Sandbox Code Playgroud)

如何调试转换:

当您在打开活动时为幻灯片转换设置非常慢的持续时间时,它会变得更加明显.

为了(视觉上)调试过渡,在开发设置中有3个选项("窗口动画比例","过渡动画比例","动画持续时间比例"),以乘以所有过渡/动画的持续时间.