הסתרת סרגלי המערכת למצב של צפייה היקפית

כדי ליהנות מחוויית הצפייה הטובה ביותר בחלק מהתכנים, מומלץ להפעיל אותם במסך מלא בלי שיוצגו אינדיקטורים בסרגל המצב או בסרגל הניווט. לדוגמה: סרטונים, משחקים, גלריות תמונות, ספרים ושקפים של מצגות. המצב הזה נקרא מצב אימרסיבי. בדף הזה מוסבר איך אפשר לעודד משתמשים להתעמק בתוכן במסך מלא.

איור 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() כדי לציין את ההתנהגות של סרגלי המערכת המוסתרים כשהמשתמשים מבצעים איתם אינטראקציה.

  • משתמשים ב-WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_TOUCH כדי להציג את סרגלי המערכת המוסתרים בכל האינטראקציות של המשתמשים במסך המתאים.

  • משתמשים ב-WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_SWIPE כדי לחשוף סרגלי מערכת מוסתרים בכל תנועות המערכת, כמו החלקה מהקצה של המסך שבו הסרגל מוסתר.

  • אפשר להשתמש ב-WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE כדי להציג באופן זמני את סרגלי המערכת המוסתרים באמצעות תנועות במערכת, כמו החלקה מהקצה של המסך שבו הסרגל מוסתר. סרגלי המערכת האלה הם זמניים, הם מוצגים כשכבת-על על תוכן האפליקציה, יכול להיות שהם שקופים במידה מסוימת והם מוסתרים אוטומטית אחרי פסק זמן קצר.