简体   繁体   English

用户手动向上滚动导航栏后如何再次隐藏导航栏?

[英]How to hide navigation bar again after user scrolled it manually up?

In a certain activity in my app I am hiding the navigation bar since that activity is full screen.在我的应用程序的某个活动中,我隐藏了导航栏,因为该活动是全屏的。 To hide the navigation bar I am using the following code:要隐藏导航栏,我使用以下代码:

    private void hideSystemUI() {
        // Enables regular immersive mode.
        // For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
        // Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_IMMERSIVE
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
        );
    }

This code works fine until the user swipes up the navigation bar.在用户向上滑动导航栏之前,此代码可以正常工作。 It then stays there.然后它就呆在那里。 What I want is that it hides again after 2 seconds or so.我想要的是它会在 2 秒左右后再次隐藏。 Is there a way to achieve this?有没有办法做到这一点?

I appreciate any help!我很感激任何帮助!

You can Use this code:您可以使用此代码:

private FullScreenListener fullScreenListener = new FullScreenListener();
private void initUiFlags() {
    int flags = View.SYSTEM_UI_FLAG_VISIBLE;

    flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;

    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(flags);
    decorView.setOnSystemUiVisibilityChangeListener(fullScreenListener);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM