简体   繁体   English

如何使状态栏/导航栏在 Android 上不可见,同时保持屏幕顶部/底部的填充?

[英]How can I make the status bar / navigation bar invisible on Android, while keeping the padding at the top / bottom of the screen?

I'm trying to create an 'immersive mode' in my app, where tapping a button simply hides the status bar (and nav bar, if possible.) But I specifically don't want the whole app to resize itself so that the content moves up to fill the space where the status bar used to be -- I just want that top part of the screen to be filled with the same background colour it had before.我正在尝试在我的应用程序中创建一个“沉浸式模式”,点击一个按钮只会隐藏状态栏(和导航栏,如果可能的话)。但我特别不希望整个应用程序自行调整大小,以便内容向上移动以填充状态栏曾经所在的空间——我只希望屏幕的顶部填充与之前相同的背景颜色。 Ideally from the user's point of view, the status bar notification icons / time / battery / etc. icons would just fade in and out.理想情况下,从用户的角度来看,状态栏通知图标/时间/电池等图标会淡入淡出。 How can I achieve this?我怎样才能做到这一点?

The effect I'm looking for is basically what the Spotify app does on the Now Playing screen when the song has a 'Canvas' (the looping video that plays along with a song) -- tapping the background causing the Now playing UI to fade out, along with the status bar.我正在寻找的效果基本上是当歌曲有“画布”(与歌曲一起播放的循环视频)时 Spotify 应用程序在“正在播放”屏幕上所做的——点击背景导致正在播放 UI 淡出出来,连同状态栏。 So it must be possible!所以这一定是可能的!

Additionally, if the phone has a notch of some sort, I don't want the status bar to become completely black, as happens with some approaches to this I've seen.此外,如果手机有某种缺口,我不希望状态栏变成全黑,就像我见过的一些解决方法一样。

Here's the doc for the status bar and the doc for the navigation bar是状态栏文档和导航栏的文档

I think what you are looking for is something like this:我认为您正在寻找的是这样的:

View decorView = getWindow().getDecorView();
// Hide the status bar and navigation bar
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();

You can transparent the status bar你可以透明状态栏

<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

For hiding StatusBar用于隐藏 StatusBar

if (Build.VERSION.SDK_INT < 16) {
    window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
} else if (Build.VERSION.SDK_INT < 30) {
    window.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
    actionBar?.hide()
} else {
    window.decorView.windowInsetsController?.hide(WindowInsets.Type.statusBars())
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 隐藏顶部状态栏但保留底部导航栏 - Hiding top status bar but keeping the bottom navigation bar 如何使应用程序全屏并摆脱顶部状态栏+底部手势? - How can I make an app fullscreen and get rid of top status bar + bottom gesture? 如何在Android中使底部导航栏不透明? - How to make bottom navigation bar opaque in android? 如何在 Android AccessibilityService 中查找状态栏、导航栏和屏幕的尺寸 - How to find dimensions for status bar, navigation bar and screen in Android AccessibilityService 如何将底部导航栏实现为Android应用程序? - How can I implement the bottom navigation bar into an app for android? 如何在顶部底部的android上添加栏? - How can I add a Bar on top bottom android? 当我隐藏底部导航或顶部栏时如何防止延迟屏幕效果? - When i hide bottom navigation or top bar How do I prevent the delayed screen effect? 如何在 android 工作室中使用 java 使 android 中的状态栏和底部导航透明? - How to make status bar and bottom navigation transparent in android using java in android studio? 如何制作这个底部导航栏? - How to make this bottom navigation bar? 如图所示,如何在 android 中为底部导航栏设置顶部边框 - how to set top border for bottom navigation bar in android as shown in image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM