调暗系统栏(已废弃)
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
<ph type="x-smartling-placeholder">
本课介绍了如何调暗系统栏(即
。Android 不提供调暗
系统栏。
使用此方法时,内容大小不会调整,但系统栏中的图标会调整
视觉上会下滑用户触摸导航栏或导航栏区域后,
两个条形都完全可见。这种技术的优势
但条形依然存在,但细节被遮盖
营造一种身临其境的体验,同时又不容易进入酒吧。
调暗状态栏和导航栏
您可以使用
SYSTEM_UI_FLAG_LOW_PROFILE
标志,如下所示:
Kotlin
// This example uses decor view, but you can use any visible view.
activity?.window?.decorView?.apply {
systemUiVisibility = View.SYSTEM_UI_FLAG_LOW_PROFILE
}
Java
// This example uses decor view, but you can use any visible view.
View decorView = getActivity().getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_LOW_PROFILE;
decorView.setSystemUiVisibility(uiOptions);
用户一轻触状态栏或导航栏,该标记即被清除。
导致条形变暗标记被清除后,您的应用需要重置
如果您想再次调暗黑边。
图 1 显示了一张导航栏处于灰显状态的图库图片(请注意,图库应用
完全隐藏状态栏;它不会调暗屏幕)。请注意,导航栏(右侧)
有微弱的白点,表示导航控件:
图 1. 调暗的系统栏。
图 2 所示为同一图库图片,但显示了系统栏:
图 2. 可见的系统栏。
显示状态栏和导航栏
如果您想以程序化方式清除通过
setSystemUiVisibility()
,您可以
如下所示:
Kotlin
activity?.window?.decorView?.apply {
// Calling setSystemUiVisibility() with a value of 0 clears
// all flags.
systemUiVisibility = 0
}
Java
View decorView = getActivity().getWindow().getDecorView();
// Calling setSystemUiVisibility() with a value of 0 clears
// all flags.
decorView.setSystemUiVisibility(0);
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Dim the system bars (deprecated)\n\n| **Deprecated:** [setSystemUiVisibility](/reference/android/view/View#setSystemUiVisibility(int)) is deprecated in API Level 30\n\nThis lesson describes how to dim the system bars (that is, the status and the navigation\nbars) on Android 4.0 (API level 14) and higher. Android does not provide a built-in way to dim the\nsystem bars on earlier versions.\n\nWhen you use this approach, the content doesn't resize, but the icons in the system bars\nvisually recede. As soon as the user touches either the status bar or the navigation bar area of\nthe screen, both bars become fully visible. The advantage of this\napproach is that the bars are still present but their details are obscured, thus\ncreating an immersive experience without sacrificing easy access to the bars.\n\nDim the Status and Navigation Bars\n----------------------------------\n\nYou can dim the status and navigation bars using the\n[SYSTEM_UI_FLAG_LOW_PROFILE](/reference/android/view/View#SYSTEM_UI_FLAG_LOW_PROFILE) flag, as follows: \n\n### Kotlin\n\n```kotlin\n// This example uses decor view, but you can use any visible view.\nactivity?.window?.decorView?.apply {\n systemUiVisibility = View.SYSTEM_UI_FLAG_LOW_PROFILE\n}\n```\n\n### Java\n\n```java\n// This example uses decor view, but you can use any visible view.\nView decorView = getActivity().getWindow().getDecorView();\nint uiOptions = View.SYSTEM_UI_FLAG_LOW_PROFILE;\ndecorView.setSystemUiVisibility(uiOptions);\n```\n\nAs soon as the user touches the status or navigation bar, the flag is cleared,\ncausing the bars to be undimmed. Once the flag has been cleared, your app needs to reset\nit if you want to dim the bars again.\n\nFigure 1 shows a gallery image in which the navigation bar is dimmed (note that the Gallery app\ncompletely hides the status bar; it doesn't dim it). Notice that the navigation bar (right\nside of the image) has faint white dots on it to represent the navigation controls:\n\n\n**Figure 1.** Dimmed system bars.\n\nFigure 2 shows the same gallery image, but with the system bars displayed:\n\n\n**Figure 2.** Visible system bars.\n\nReveal the Status and Navigation Bars\n-------------------------------------\n\nIf you want to programmatically clear flags set with\n[setSystemUiVisibility()](/reference/android/view/View#setSystemUiVisibility(int)), you can do so\nas follows: \n\n### Kotlin\n\n```kotlin\nactivity?.window?.decorView?.apply {\n // Calling setSystemUiVisibility() with a value of 0 clears\n // all flags.\n systemUiVisibility = 0\n}\n```\n\n### Java\n\n```java\nView decorView = getActivity().getWindow().getDecorView();\n// Calling setSystemUiVisibility() with a value of 0 clears\n// all flags.\ndecorView.setSystemUiVisibility(0);\n```"]]