如果可能,我想删除它.我正在使用黑色背景的活动,同样的活动也有一个工具栏和一个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)利用在棒棒糖(Activity& Fragment Transitions)中引入的转换.观察到的“白色屏幕”是窗口背景,即在转换期间正在褪色(more info about Activity & Fragment Transitions ).我想你在您的布局的根视图中设置您的活动的“黑色背景”?将窗口背景设置为黑色可以解决您的问题.
编程方式:
window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
主题:
<item name="android:windowBackground">@android:color/black</item>
这是由此产生的过渡.
编辑:如何提供required滑出(左)转换的呼叫活动
第一个活动:
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)); }
第二活动:
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); 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)); }
您可以尝试不同的内插器来改变转换的速度.
LinearInterpolator的最终过渡:
如果你想摆脱第一个幻灯片和第二个活动的幻灯片之间的差距,你可以设置:
<item name="android:windowAllowEnterTransitionOverlap">true</item>
如何调试转换:
It can become a lot more apparent when you set a very slow duration to the Slide transition when opening an activity.
为了(视觉)调试转换,在开发设置中有3个选项(“窗口动画缩放”,“过渡动画缩放”,“动画持续时间缩放”),以乘以所有转换/动画的持续时间.