隐藏状态栏的android状态栏、android

2023-09-07 12:29:48 作者:恶劣趣

如何隐藏状态栏安卓4.1.2? 我想解决办法隐藏在4.1.2版本的状态栏

How to hide status bar android 4.1.2 ? i want solution to hide the status bar on version 4.1.2

我要隐藏状态栏在我的应用程序

i want to hide status bar on my application

LinearLayout layout = (LinearLayout)findViewById(R.id.layout);    
layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

这code不能在4.1.2版本下工作

this code not work on version 4.1.2

推荐答案

由于杰利贝恩(4.1)有一个不依赖于窗口管理新方法。而是使用setSystemUiVisibility关窗的,这给你更精确地控制系统的酒吧比使用窗口管理标志。下面是一个完整的例子:

Since Jellybean (4.1) there is a new method that doesn't rely on the WindowManager. Instead use setSystemUiVisibility off of the Window, this gives you more granular control over the system bars than using WindowManager flags. Here is a full example:

if (Build.VERSION.SDK_INT < 16) { //ye olde method
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else { // Jellybean and up, new hotness
    View decorView = getWindow().getDecorView();
    // Hide the status bar.
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);
    // Remember that you should never show the action bar if the
    // status bar is hidden, so hide that too if necessary.
    ActionBar actionBar = getActionBar();
    actionBar.hide();
}