إخفاء أشرطة النظام للوضع الغامر
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
من الأفضل الاستمتاع ببعض المحتوى في وضع ملء الشاشة بدون أي مؤشرات على شريط الحالة أو شريط التنقّل. وتشمل بعض الأمثلة الفيديوهات والألعاب ومعارض الصور والكتب وشرائح العروض التقديمية. ويُشار إلى ذلك باسم الوضع الغامر. توضّح هذه الصفحة كيف يمكنك جذب المستخدمين بشكل أكبر من خلال عرض المحتوى بملء الشاشة.
الشكل 1. مثال على وضع العرض المجسم
يساعد وضع العرض الغامر المستخدمين على تجنُّب الخروج من اللعبة بدون قصد،
ويوفّر تجربة غامرة للاستمتاع بالصور والفيديوهات والكتب.
ومع ذلك، يجب الانتباه إلى عدد المرات التي ينتقل فيها المستخدمون من تطبيق إلى آخر للتحقّق من الإشعارات أو إجراء عمليات بحث عشوائية أو اتّخاذ إجراءات أخرى. بما أنّ وضع العرض الغامر
يؤدي إلى فقدان المستخدمين إمكانية الوصول بسهولة إلى عناصر التنقّل في النظام، لا تستخدم وضع العرض الغامر إلا
عندما تتجاوز الفائدة التي تعود على تجربة المستخدم مجرد استخدام مساحة شاشة إضافية.
استخدِم WindowInsetsControllerCompat.hide()
لإخفاء أشرطة النظام وWindowInsetsControllerCompat.show()
لإظهارها مجددًا.
يوضّح المقتطف التالي مثالاً على ضبط زر لإخفاء أشرطة النظام وإظهارها.
Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
...
val windowInsetsController =
WindowCompat.getInsetsController(window, window.decorView)
// Configure the behavior of the hidden system bars.
windowInsetsController.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
// Add a listener to update the behavior of the toggle fullscreen button when
// the system bars are hidden or revealed.
ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { view, windowInsets ->
// You can hide the caption bar even when the other system bars are visible.
// To account for this, explicitly check the visibility of navigationBars()
// and statusBars() rather than checking the visibility of systemBars().
if (windowInsets.isVisible(WindowInsetsCompat.Type.navigationBars())
|| windowInsets.isVisible(WindowInsetsCompat.Type.statusBars())) {
binding.toggleFullscreenButton.setOnClickListener {
// Hide both the status bar and the navigation bar.
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
}
} else {
binding.toggleFullscreenButton.setOnClickListener {
// Show both the status bar and the navigation bar.
windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
}
}
ViewCompat.onApplyWindowInsets(view, windowInsets)
}
}
Java
@Override
protected void onCreate(Bundle savedInstanceState) {
...
WindowInsetsControllerCompat windowInsetsController =
WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView());
// Configure the behavior of the hidden system bars.
windowInsetsController.setSystemBarsBehavior(
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
);
// Add a listener to update the behavior of the toggle fullscreen button when
// the system bars are hidden or revealed.
ViewCompat.setOnApplyWindowInsetsListener(
getWindow().getDecorView(),
(view, windowInsets) -> {
// You can hide the caption bar even when the other system bars are visible.
// To account for this, explicitly check the visibility of navigationBars()
// and statusBars() rather than checking the visibility of systemBars().
if (windowInsets.isVisible(WindowInsetsCompat.Type.navigationBars())
|| windowInsets.isVisible(WindowInsetsCompat.Type.statusBars())) {
binding.toggleFullscreenButton.setOnClickListener(v -> {
// Hide both the status bar and the navigation bar.
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());
});
} else {
binding.toggleFullscreenButton.setOnClickListener(v -> {
// Show both the status bar and the navigation bar.
windowInsetsController.show(WindowInsetsCompat.Type.systemBars());
});
}
return ViewCompat.onApplyWindowInsets(view, windowInsets);
});
}
يمكنك اختياريًا تحديد نوع أشرطة النظام التي تريد إخفاءها وتحديد سلوكها عندما يتفاعل المستخدم معها.
تحديد أشرطة النظام المطلوب إخفاؤها
لتحديد نوع أشرطة النظام التي تريد إخفاءها، مرِّر إحدى المَعلمات التالية إلى WindowInsetsControllerCompat.hide()
.
تحديد سلوك أشرطة النظام المخفية
استخدِم WindowInsetsControllerCompat.setSystemBarsBehavior()
لتحديد طريقة عمل أشرطة النظام المخفية عندما يتفاعل المستخدم معها.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Hide system bars for immersive mode\n\nSome content is best experienced in fullscreen without any indicators on the\nstatus bar or the navigation bar. Some examples are videos, games, image\ngalleries, books, and presentation slides. This is referred to as\n*immersive mode*. This page shows how you can engage users more deeply with\ncontent in fullscreen. \n**Figure 1.** Example of immersive mode.\n\nImmersive mode helps users avoid accidental exits during a game and\ndelivers an immersive experience for enjoying images, videos, and books.\nHowever, be mindful of how often users jump in and out of apps to check notifications,\nto conduct impromptu searches, or to take other actions. Because immersive mode\ncauses users to lose easy access to system navigation, use immersive mode only\nwhen the benefit to the user experience goes beyond simply using extra screen\nspace.\n\nUse [`WindowInsetsControllerCompat.hide()`](/reference/androidx/core/view/WindowInsetsControllerCompat#hide(int))\nto hide the system bars and [`WindowInsetsControllerCompat.show()`](/reference/androidx/core/view/WindowInsetsControllerCompat#show(int))\nto bring them back.\n\nThe following snippet shows an example of configuring a button to hide and show\nthe system bars. \n\n### Kotlin\n\n```kotlin\noverride fun onCreate(savedInstanceState: Bundle?) {\n ...\n\n val windowInsetsController =\n WindowCompat.getInsetsController(window, window.decorView)\n // Configure the behavior of the hidden system bars.\n windowInsetsController.systemBarsBehavior =\n WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE\n\n // Add a listener to update the behavior of the toggle fullscreen button when\n // the system bars are hidden or revealed.\n ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { view, windowInsets -\u003e\n // You can hide the caption bar even when the other system bars are visible.\n // To account for this, explicitly check the visibility of navigationBars()\n // and statusBars() rather than checking the visibility of systemBars().\n if (windowInsets.isVisible(WindowInsetsCompat.Type.navigationBars())\n || windowInsets.isVisible(WindowInsetsCompat.Type.statusBars())) {\n binding.toggleFullscreenButton.setOnClickListener {\n // Hide both the status bar and the navigation bar.\n windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())\n }\n } else {\n binding.toggleFullscreenButton.setOnClickListener {\n // Show both the status bar and the navigation bar.\n windowInsetsController.show(WindowInsetsCompat.Type.systemBars())\n }\n }\n ViewCompat.onApplyWindowInsets(view, windowInsets)\n }\n}\n```\n\n### Java\n\n```java\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\n ...\n\n WindowInsetsControllerCompat windowInsetsController =\n WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView());\n // Configure the behavior of the hidden system bars.\n windowInsetsController.setSystemBarsBehavior(\n WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE\n );\n\n // Add a listener to update the behavior of the toggle fullscreen button when\n // the system bars are hidden or revealed.\n ViewCompat.setOnApplyWindowInsetsListener(\n getWindow().getDecorView(),\n (view, windowInsets) -\u003e {\n // You can hide the caption bar even when the other system bars are visible.\n // To account for this, explicitly check the visibility of navigationBars()\n // and statusBars() rather than checking the visibility of systemBars().\n if (windowInsets.isVisible(WindowInsetsCompat.Type.navigationBars())\n || windowInsets.isVisible(WindowInsetsCompat.Type.statusBars())) {\n binding.toggleFullscreenButton.setOnClickListener(v -\u003e {\n // Hide both the status bar and the navigation bar.\n windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());\n });\n } else {\n binding.toggleFullscreenButton.setOnClickListener(v -\u003e {\n // Show both the status bar and the navigation bar.\n windowInsetsController.show(WindowInsetsCompat.Type.systemBars());\n });\n }\n return ViewCompat.onApplyWindowInsets(view, windowInsets);\n });\n}\n```\n\nOptionally, you can specify the type of system bars to hide and determine\ntheir behavior when a user interacts with them.\n\n#### Specify which system bars to hide\n\nTo specify the type of system bars to hide, pass one of the following parameters\nto `WindowInsetsControllerCompat.hide()`.\n\n- Use [`WindowInsetsCompat.Type.systemBars()`](/reference/kotlin/androidx/core/view/WindowInsetsCompat.Type#systembars) to\n hide both system bars.\n\n- Use [`WindowInsetsCompat.Type.statusBars()`](/reference/kotlin/androidx/core/view/WindowInsetsCompat.Type#statusbars) to\n hide only the status bar.\n\n- Use [`WindowInsetsCompat.Type.navigationBars()`](/reference/kotlin/androidx/core/view/WindowInsetsCompat.Type#navigationbars) to\n hide only the navigation bar.\n\n#### Specify behavior of hidden system bars\n\nUse [`WindowInsetsControllerCompat.setSystemBarsBehavior()`](/reference/androidx/core/view/WindowInsetsControllerCompat#setSystemBarsBehavior(int))\nto specify how hidden system bars behave when the user interacts with them.\n\n- Use [`WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_TOUCH`](/reference/androidx/core/view/WindowInsetsControllerCompat#BEHAVIOR_SHOW_BARS_BY_TOUCH())\n to reveal hidden system bars on *any* user interactions on the corresponding\n display.\n\n- Use [`WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_SWIPE`](/reference/androidx/core/view/WindowInsetsControllerCompat#BEHAVIOR_SHOW_BARS_BY_SWIPE())\n to reveal hidden system bars on any system gestures, such as swiping from\n the edge of the screen where the bar is hidden from.\n\n- Use [`WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE`](/reference/androidx/core/view/WindowInsetsControllerCompat#BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE())\n to temporarily reveal hidden system bars with system gestures, such as\n swiping from the edge of the screen where the bar is hidden from. These\n transient system bars overlay your app's content, might have some degree of\n transparency, and are automatically hidden after a short timeout."]]