יש תכנים שעדיף לצפות בהם במסך מלא בלי אינדיקטורים בשורת הסטטוס או בסרגל הניווט. לדוגמה: סרטונים, משחקים, גלריות תמונות, ספרים ושקפים במצגת. המצב הזה נקרא מצב אימרסיבי. בדף הזה מוסבר איך להגביר את מעורבות המשתמשים באמצעות תוכן במסך מלא.
מצב אימרסיבי עוזר למשתמשים להימנע מיציאות מקריות במהלך משחק, ומספק חוויה אימרסיבית שמאפשרת ליהנות מתמונות, מסרטונים ומספרים. עם זאת, חשוב לשים לב לתדירות שבה המשתמשים נכנסים לאפליקציות ויוצאים מהן כדי לבדוק התראות, לבצע חיפושים מאולתרים או לבצע פעולות אחרות. במצב אימרסיבי המשתמשים מאבדים את הגישה הנוחה לניווט במערכת, לכן כדאי להשתמש במצב הזה רק כשהתועלת לחוויית המשתמש גדולה יותר מהשימוש בשטח הנוסף במסך.
כדי להסתיר את סרגלי המידע, משתמשים ב-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().
משתמשים ב-
WindowInsetsCompat.Type.systemBars()כדי להסתיר את שני סרגלי המידע.משתמשים ב-
WindowInsetsCompat.Type.statusBars()כדי להסתיר רק את שורת הסטטוס.משתמשים ב-
WindowInsetsCompat.Type.navigationBars()כדי להסתיר רק את סרגל הניווט.
הגדרת ההתנהגות של סרגלי מידע מוסתרים
משתמשים ב-WindowInsetsControllerCompat.setSystemBarsBehavior() כדי לציין איך סרגלי מידע מוסתרים מתנהגים כשהמשתמשים יוצרים איתם אינטראקציה.
משתמשים ב-
WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_TOUCHכדי לחשוף סרגלי מידע מוסתרים בכל אינטראקציה של המשתמש במסך המתאים.כדי להציג סרגלי מידע מוסתרים, משתמשים ב-
WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_SWIPEבכל תנועה מובנית במערכת, כמו החלקה מקצה המסך שבו הסרגל מוסתר.אפשר להשתמש ב-
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPEכדי להציג באופן זמני סרגלי מידע מוסתרים באמצעות תנועות מובנות במערכת, כמו החלקה מהקצה של המסך שבו הסרגל מוסתר. סרגלי המידע הזמניים האלה מופיעים מעל התוכן של האפליקציה, יכול להיות שהם יהיו שקופים במידה מסוימת, והם מוסתרים באופן אוטומטי אחרי זמן קצר.