删除幻灯片窗口过渡启动时创建的白屏 [英] Remove the white screen a Slide window transition creates when it starts

查看:136
本文介绍了删除幻灯片窗口过渡启动时创建的白屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用黑色背景的活动.该活动同时具有工具栏和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);
    }

我的风格

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

解决方案

如何为开始的活动转换幻灯片时修复白屏:

karaokyos答案利用了之前的棒棒糖 活动过渡.这些过渡以整个活动屏幕为目标,并且不提供在过渡期间将屏幕的某些部分排除在外的功能.

约翰·欧内斯特·瓜达卢佩(John Ernest Guadalupe)方法利用了棒棒糖中引入的过渡(活动和片段过渡).观察到的白屏"是窗口背景,在过渡期间逐渐淡出().我猜您是在布局的根视图中设置活动的黑色背景"吗?将窗口背景设置为黑色应该可以解决您的问题.

以编程方式:

window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));

主题:

<item name="android:windowBackground">@android:color/black</item>

这是最终的过渡.

如何提供

如何调试转换:

如果您在打开活动时将幻灯片过渡的持续时间设置得很慢,就会变得更加明显.

要(直观地)调试过渡,开发设置中有3个选项(窗口动画比例",过渡动画比例",动画持续时间比例"),以乘以所有过渡/动画的持续时间.

I am using an activity with a black background. That same activity has a toolbar and a DrawerLayout as well. This white screen makes the look inconsistent.

It can become more apparent when there is a very slow Slide transition when opening an activity.

Is there any way to remove this?

Code that sets the enter transition on the second activity:

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

My styles

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

解决方案

How to fix the white screen during the slide in transition for the started activity:

karaokyos answer utilizes the pre Lollipop activity transitions. These transitions target the whole activity screen and don't provide capabilities to exclude parts of the screen during the transition.

John Ernest Guadalupe approach utilizes the transitions introduced in Lollipop (Activity & Fragment Transitions). The observed "white screen" is the window background, that is fading in during the transition (more info about Activity & Fragment Transitions ). I guess you are setting the "black background" of your activities in the root view of your layout? Setting the window background to black should solve your problem.

Programmatically:

window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));

Theme:

<item name="android:windowBackground">@android:color/black</item>

This is the resulting transition.

Edit: How to provide the required slide out (left) transition for the calling activity

First Activity:

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

Second Activity:

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

You can try different interpolators to change the pace of the transition.

Resulting transition with LinearInterpolator:

If you want to get rid of the gap between the slide out of the first and slide in of the second activity you can set:

<item name="android:windowAllowEnterTransitionOverlap">true</item>

How to debug transitions:

It can become a lot more apparent when you set a very slow duration to the Slide transition when opening an activity.

To (visually) debug transitions there are 3 options ("Window animation scale","Transition animation scale", "Animation duration scale") in the development settings to multiply the duration of all transitions/animations.

这篇关于删除幻灯片窗口过渡启动时创建的白屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆