Gerçekçi mod için sistem çubuklarını gizle

Bazı içerikler, durum çubuğunda veya gezinme çubuğunda herhangi bir gösterge olmadan tam ekranda en iyi şekilde deneyimlenir. Videolar, oyunlar, resim galerileri, kitaplar ve sunu slaytları bunlara örnek olarak verilebilir. Buna yoğun içerik modu denir. Bu sayfada, tam ekran içeriklerle kullanıcıların ilgisini nasıl daha fazla çekebileceğiniz gösterilmektedir.

Şekil 1. Yoğun içerik modu örneği.

Yoğun içerik modu, kullanıcıların oyun sırasında yanlışlıkla çıkış yapmasını önlemeye yardımcı olur ve resim, video ve kitapların keyfini çıkarmak için yoğun içerik deneyimi sunar. Ancak kullanıcıların bildirimleri kontrol etmek, anlık aramalar yapmak veya başka işlemler gerçekleştirmek için uygulamalara ne sıklıkta girip çıktığını göz önünde bulundurun. Yoğun içerik modu, kullanıcıların sistem gezinme özelliklerine kolayca erişmesini engellediğinden bu modu yalnızca kullanıcı deneyimine sağladığı fayda, fazladan ekran alanı kullanmanın ötesine geçtiğinde kullanın.

Sistem çubuklarını gizlemek için WindowInsetsControllerCompat.hide(), geri getirmek için WindowInsetsControllerCompat.show() kullanın.

Aşağıdaki snippet'te, sistem çubuklarını gizlemek ve göstermek için bir düğmenin nasıl yapılandırılacağı gösterilmektedir.

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);
    });
}

İsteğe bağlı olarak, gizlenecek sistem çubuklarının türünü belirtebilir ve kullanıcı bunlarla etkileşime girdiğinde davranışlarını belirleyebilirsiniz.

Gizlenecek sistem çubuklarını belirtin

Gizlenecek sistem çubuklarının türünü belirtmek için WindowInsetsControllerCompat.hide() yöntemine aşağıdaki parametrelerden birini iletin.

Gizli sistem çubuklarının davranışını belirtme

Kullanıcı etkileşimde bulunduğunda gizli sistem çubuklarının nasıl davranacağını belirtmek için WindowInsetsControllerCompat.setSystemBarsBehavior() kullanın.