沉浸模式显示空白 [英] Immersive Mode showing blank space
本文介绍了沉浸模式显示空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试实现全屏模式,但是对于Android 4.4及更高版本,它在那里显示了空白:
I'm trying to implement a fullscreen mode, but for Android 4.4 and up, it shows a blank space there:
先于沉浸模式(全屏)
和之后 toggleFullScreen
(假);
如您所见,它不会 删除 .这是我用来切换它的代码:
as you can see, its doesn't remove it. Here's the code that I'm using to toggle it:
public void toggleFullscreen(boolean fs) {
if (Build.VERSION.SDK_INT >= 11) {
// The UI options currently enabled are represented by a bitfield.
// getSystemUiVisibility() gives us that bitfield.
int uiOptions = this.getWindow().getDecorView().getSystemUiVisibility();
int newUiOptions = uiOptions;
boolean isImmersiveModeEnabled =
((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
if (isImmersiveModeEnabled) {
Log.i(getPackageName(), "Turning immersive mode mode off. ");
} else {
Log.i(getPackageName(), "Turning immersive mode mode on.");
}
// Navigation bar hiding: Backwards compatible to ICS.
if (Build.VERSION.SDK_INT >= 14) {
newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
// Status bar hiding: Backwards compatible to Jellybean
if (Build.VERSION.SDK_INT >= 16) {
newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
}
// Immersive mode: Backward compatible to KitKat.
// Note that this flag doesn't do anything by itself, it only augments the behavior
// of HIDE_NAVIGATION and FLAG_FULLSCREEN. For the purposes of this sample
// all three flags are being toggled together.
// Note that there are two immersive mode UI flags, one of which is referred to as "sticky".
// Sticky immersive mode differs in that it makes the navigation and status bars
// semi-transparent, and the UI flag does not get cleared when the user interacts with
// the screen.
if (Build.VERSION.SDK_INT >= 18) {
newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
} else {
// for android pre 11
WindowManager.LayoutParams attrs = getWindow().getAttributes();
if (fs) {
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
} else {
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
}
this.getWindow().setAttributes(attrs);
}
try {
// hide actionbar
if
(this instanceof AppCompatActivity) {
if (fs) getSupportActionBar().hide();
else getSupportActionBar().show();
} else if
(Build.VERSION.SDK_INT >= 11) {
if (fs) getActionBar().hide();
else getActionBar().show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
推荐答案
请检查您的布局中是否没有android:fitsSystemWindows="true"
.
Please check that you don't have android:fitsSystemWindows="true"
in your layout.
至少它解决了我的情况-我在FrameLayout上安装了fitsSystemWindows.
At least it solved my case - I had fitsSystemWindows on FrameLayout.
这篇关于沉浸模式显示空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文