使用沉浸式模式的应用程序在等待一段时间后返回到应用程序时,会在屏幕底部留下一个黑条(活动被破坏)。
正在发生的事情:(我启用了开发人员选项:“不要保留活动”来复制这个选项)。

这个bug也只出现在棒棒糖上,而不是KitKat上。
我已经取消了这个应用程序,只是简单地启动了一个虚拟活动,除了设置系统UI标志之外,没有任何功能:
public class DummyActivity extends FragmentActivity {
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
setSystemUiVisibility();
}
}
public void setSystemUiVisibility() {
if (getWindow() != null && getWindow().getDecorView() != null) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
}编辑:在创建了一个只使用此活动的新项目之后,我在使用扩展“android:Theme.Holo”的应用主题时看到了这个问题的重现,并在扩展材料主题时修复了这个示例项目中的问题:
变化
<style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
</style>至
<style name="AppTheme"parent="android:Theme.Material.Light.NoActionBar.Fullscreen">
</style>不幸的是,这个修复没有解决我的主要项目中的问题,但它使我更接近解决方案,并可能帮助其他人解决相同的问题。
发布于 2016-06-15 23:43:18
我也有同样的问题。下面是我做的一些更新,让它消失了。希望其中之一对你有用!
activity_main.xml
android:fitsSystemWindows="false"风格-v21
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowSharedElementsUseOverlay">false</item>MainActivity.java
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_FULLSCREEN
);发布于 2016-08-01 07:34:40
使用
<style name="AppTheme"parent="android:Theme.Material.Light.NoActionBar.Fullscreen"> </style>确实解决了这个问题,但它只适用于api:21。
为了让它适用于所有的系统。您可以在res目录中创建一个名为style-v21的目录,并将该style.xml放在那里。Android系统足够聪明,可以选择新的还是旧的手机。
发布于 2020-04-23 19:04:57
对我来说,上面是个黑色的酒吧。关键是活动风格的这一点:
// Important to draw behind cutouts
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> 这是我的代码:
1-活动
private fun hideSystemUI() {
sysUIHidden = true
// Enables regular immersive mode.
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// Hide the nav bar and status bar
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // Hide nav bar
or View.SYSTEM_UI_FLAG_FULLSCREEN // Hide status bar
)
}
private fun showSystemUI() {
sysUIHidden = false
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // layout Behind nav bar
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // layout Behind status bar
)
}2- xml布局的根视图
android:fitsSystemWindows="false"全屏幕活动的3种样式:
<style name="FullscreenTheme" parent="AppTheme">
<item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">@null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
<item name="android:statusBarColor">#50000000</item>
<item name="android:navigationBarColor">#50000000</item>
// Important to draw behind cutouts
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/sysTransparent</item>
</style>https://stackoverflow.com/questions/28703306
复制相似问题