ইমারসিভ মোডের জন্য সিস্টেম বার লুকান

কিছু কন্টেন্ট পূর্ণস্ক্রিনে সবচেয়ে ভালোভাবে দেখা যায়, স্ট্যাটাস বার বা নেভিগেশন বারে কোনও ইন্ডিকেটর ছাড়াই। কিছু উদাহরণ হল ভিডিও, গেম, ইমেজ গ্যালারি, বই এবং প্রেজেন্টেশন স্লাইড। এটিকে ইমারসিভ মোড বলা হয়। এই পৃষ্ঠাটি দেখায় কিভাবে আপনি পূর্ণস্ক্রিনে কন্টেন্টের সাথে ব্যবহারকারীদের আরও গভীরভাবে জড়িত করতে পারেন।

চিত্র ১. ইমারসিভ মোডের উদাহরণ।

ইমারসিভ মোড ব্যবহারকারীদের গেম চলাকালীন দুর্ঘটনাজনিত প্রস্থান এড়াতে সাহায্য করে এবং ছবি, ভিডিও এবং বই উপভোগ করার জন্য একটি নিমজ্জিত অভিজ্ঞতা প্রদান করে। তবে, নোটিফিকেশন চেক করতে, তাৎক্ষণিক অনুসন্ধান পরিচালনা করতে বা অন্যান্য পদক্ষেপ নিতে ব্যবহারকারীরা কত ঘন ঘন অ্যাপে প্রবেশ করে এবং বেরিয়ে আসে সেদিকে খেয়াল রাখুন। যেহেতু ইমারসিভ মোড ব্যবহারকারীদের সিস্টেম নেভিগেশনের সহজ অ্যাক্সেস হারাতে বাধ্য করে, তাই শুধুমাত্র তখনই ইমারসিভ মোড ব্যবহার করুন যখন ব্যবহারকারীর অভিজ্ঞতার সুবিধা কেবল অতিরিক্ত স্ক্রিন স্পেস ব্যবহার করার চেয়ে বেশি হয়।

সিস্টেম বার লুকানোর জন্য WindowInsetsControllerCompat.hide() এবং সেগুলি ফিরিয়ে আনার জন্য WindowInsetsControllerCompat.show() ব্যবহার করুন।

নিম্নলিখিত স্নিপেটটি সিস্টেম বারগুলি লুকানোর এবং দেখানোর জন্য একটি বোতাম কনফিগার করার একটি উদাহরণ দেখায়।

কোটলিন

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

জাভা

@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 ব্যবহার করে লুকানো সিস্টেম বারগুলি অস্থায়ীভাবে সিস্টেম জেসচারের মাধ্যমে প্রকাশ করুন, যেমন স্ক্রিনের প্রান্ত থেকে সোয়াইপ করা যেখানে বারটি লুকানো আছে। এই ক্ষণস্থায়ী সিস্টেম বারগুলি আপনার অ্যাপের বিষয়বস্তুকে ওভারলে করে, কিছুটা স্বচ্ছতা থাকতে পারে এবং অল্প সময়ের পরে স্বয়ংক্রিয়ভাবে লুকানো হয়।