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

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

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

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

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