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

Bazı içerikler en iyi, durum çubuğunda veya gezinme çubuğunda herhangi bir gösterge olmadan tam ekranda deneyimlenir. Videolar, oyunlar, resim galerileri, kitaplar ve sunum slaytları bunlara örnek olarak verilebilir. Bu yönteme yoğun içerik modu denir. Bu sayfada, tam ekrandaki içerikle kullanıcılarla daha derin bir şekilde nasıl etkileşim kurabileceğ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 çıkmaktan kaçınmasına yardımcı olur ve resim, video ve kitapların keyfini çıkarmak için etkileyici bir deneyim sunar. Bununla birlikte, kullanıcıların bildirimleri kontrol etmek, hazırlıksız aramalar yapmak veya başka işlemler yapmak için ne sıklıkta uygulamaya girip çıktığına dikkat edin. Yoğun içerik modu, kullanıcıların sistemde gezinmeye kolayca erişememesine neden olduğundan yoğun modu yalnızca kullanıcı deneyiminin avantajı, 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() tuşunu 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ğına dair bir örnek 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, bir kullanıcı etkileşimde bulunduğunda gizlenmesini ve davranışını belirlemek üzere sistem çubuklarının türünü belirtebilirsiniz.

Hangi sistem çubuklarının gizleneceğini belirtme

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

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

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