简体   繁体   English

如何隐藏导航栏

[英]How to hide navigation bar

I've got a promblem with Android app. 我在Android应用中遇到了问题。

I use this code to hide navigation bar. 我使用此代码隐藏导航栏。

public class Initer {
    public static void fullScreen(Window window) {
        if (Build.VERSION.SDK_INT >= 19) {
            View decor = window.getDecorView();
            fullScreen(decor);
        } else {
            window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
    }

    public static void fullScreen(View decor) {
        if (Build.VERSION.SDK_INT >= 19) {
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |    
                    View.SYSTEM_UI_FLAG_FULLSCREEN |
                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }
}

But when I show PopupWindow or Dialog up, navigation bar will come up again. 但是当我显示PopupWindowDialog时,导航栏将再次出现。

I tried do this 我尝试这样做

PopupWindow popupWindow =new PopupWindow(getWindow().getContext());
View popupWindowView = LayoutInflater.from(getWindow().getContext()).
        inflate(R.layout.dialog_interval_insert, null);
Initer.fullScreen(popupWindowView);

...

popupWindow.showAsDropDown(button_start);

to hide navigation bar when PopupWindow showing up. PopupWindow出现时隐藏导航栏。 But it doesn't work. 但这是行不通的。 When I call the PopupWindow , the navigation bar will show up then hide again. 当我调用PopupWindow ,导航栏将显示然后再次隐藏。 And when I dismiss() it, navigation bar will be there. 当我dismiss()时,导航栏就会出现。

How can I hide navigation bar permanently in Whole application? 如何在整个应用程序中永久隐藏导航栏?

you can use this code 您可以使用此代码

public void FullScreen_Activity(Activity activity) {
    activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
    activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

and change StatusBar Color with 并使用更改状态栏颜色

public void setStatusBarColor(Activity activity, int RecColor) {
        if (isApi21()) {
            Window window = activity.getWindow();
            // clear FLAG_TRANSLUCENT_STATUS flag:
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            // finally change the color
            window.setStatusBarColor(ContextCompat.getColor(activity, RecColor));
        }
    }

and how to use FullScreen_Activity method 以及如何使用FullScreen_Activity方法

public class SplashActivity extends AppCompatActivity {
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getMethod().FullScreen_Activity(this);
    setContentView(R.layout.activity_splash);
    }
}

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

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