[英]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.