作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在尝试实现全屏模式,但对于 Android 4.4 及更高版本,它会在此处显示一个空白区域:
之前沉浸式模式(全屏)
和之后 toggleFullScreen
(false);
如您所见,它不会删除它。这是我用来切换它的代码:
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/
目前我正在使用低配置模式来隐藏顶部的黑色条并使底部的导航栏变暗。我想在 Android 上使用沉浸模式,但操作栏出现问题。我想做沉浸式模式,但将操作栏保持在应有的位置。有没有办法做到这一点? 这就是我
我是一名优秀的程序员,十分优秀!