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

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

איור 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 כדי לחשוף באופן זמני סרגלי מערכת מוסתרים באמצעות תנועות מערכת, כמו להחליק מקצה המסך שבו הסרגל מוסתר. האלה סרגלי מערכת זמניים מסתירים את תוכן האפליקציה, ועשויים לכלול מידה מסוימת והם מוסתרים באופן אוטומטי אחרי זמן קצוב לתפוגה.