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 en iyi şekilde tam ekranda görüntülenir. Örnek olarak videolar, oyunlar, resim galerileri, kitaplar ve sunum slaytları verilebilir. Buna kapsamlı mod adı verilir. Bu sayfada, tam ekran içerikle kullanıcılarla nasıl daha derin bir etkileşimde bulunabileceğ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ışları önlemesine yardımcı olur ve resimlerin, videoların ve kitapların keyfini sürmeleri için etkileyici bir deneyim sunar. Ancak kullanıcıların bildirimleri kontrol etmek, plansız aramalar yapmak veya başka işlemler yapmak için hangi uygulamalara girip çıktığına dikkat edin. Yoğun içerik modu, kullanıcıların sistemde gezinmeye kolay erişimi kaybetmelerine neden olduğundan, yoğun içerik modu yalnızca kullanıcı deneyiminin avantajı, ekstra ekran alanı kullanmanın ötesindeki bir avantaj olduğunda kullanın.

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

Aşağıdaki snippet'te sistem çubuklarını gizlemek ve göstermek için bir düğme yapılandırma örneği 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.
    window.decorView.setOnApplyWindowInsetsListener { 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())
            }
        }
        view.onApplyWindowInsets(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.
    getWindow().getDecorView().setOnApplyWindowInsetsListener((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 view.onApplyWindowInsets(windowInsets);
    });
}

İsteğe bağlı olarak, bir kullanıcı etkileşimde bulunduğunda gizlenecek ve davranışlarını belirlemek için sistem çubuklarının türünü belirtebilirsiniz.

Gizlenecek sistem çubuklarını belirtin

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

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

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