इमर्सिव मोड के लिए सिस्टम बार छिपाएं

कुछ कॉन्टेंट को स्टेटस बार या नेविगेशन बार पर किसी भी इंडिकेटर के बिना, फ़ुलस्क्रीन में सबसे अच्छी तरह से देखा जा सकता है. इसके कुछ उदाहरण ये हैं: वीडियो, गेम, इमेज गैलरी, किताबें, और प्रज़ेंटेशन स्लाइड. इसे इमर्सिव मोड कहा जाता है. इस पेज पर बताया गया है कि फ़ुलस्क्रीन में कॉन्टेंट दिखाकर, उपयोगकर्ताओं का जुड़ाव कैसे बढ़ाया जा सकता है.

पहली इमेज. इमर्सिव मोड का उदाहरण.

इमर्सिव मोड की मदद से, गेम खेलते समय अनजाने में गेम से बाहर निकलने से बचा जा सकता है. साथ ही, यह मोड इमेज, वीडियो, और किताबों का आनंद लेने के लिए बेहतर अनुभव देता है. हालांकि, इस बात का ध्यान रखें कि उपयोगकर्ता सूचनाएं देखने, अचानक से कुछ खोजने या अन्य कार्रवाइयां करने के लिए, कितनी बार ऐप्लिकेशन खोलते और बंद करते हैं. इमर्सिव मोड में, उपयोगकर्ताओं को सिस्टम नेविगेशन को आसानी से ऐक्सेस करने में परेशानी होती है. इसलिए, इमर्सिव मोड का इस्तेमाल सिर्फ़ तब करें, जब उपयोगकर्ता अनुभव को बेहतर बनाने के लिए, स्क्रीन के ज़्यादा स्पेस का इस्तेमाल करना ज़रूरी हो.

सिस्टम बार छिपाने के लिए 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 का इस्तेमाल करके, सिस्टम के जेस्चर की मदद से कुछ समय के लिए छिपे हुए सिस्टम बार दिखाएं. जैसे, स्क्रीन के उस किनारे से स्वाइप करें जहां बार छिपा हुआ है. ये सिस्टम बार, आपके ऐप्लिकेशन के कॉन्टेंट पर दिखते हैं. ये कुछ हद तक पारदर्शी हो सकते हैं और कुछ समय बाद अपने-आप छिप जाते हैं.