gpt4 book ai didi

android - 显示空白的沉浸式模式

转载 作者:IT老高 更新时间:2023-10-28 22:25:29 24 4
gpt4 key购买 nike

我正在尝试实现全屏模式,但对于 Android 4.4 及更高版本,它会在此处显示一个空白区域:

之前沉浸式模式(全屏)

enter image description here

之后 toggleFullScreen(false);

enter image description here

如您所见,它不会删除它。这是我用来切换它的代码:

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"

至少它解决了我的问题 - 我在 FrameLayout 上有了 fitSystemWindows。

关于android - 显示空白的沉浸式模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34408424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com