Android:禁用并启用以编程方式为API 19提取状态栏

sit*_*ail 1 android statusbar

我已经完成了隐藏状态栏的工作,但遗憾的是,一旦隐藏状态栏,我就没有找到显示它的方法.我做了很多解决方法,但仍然没有成功,无论是在这里还是在这里.

活动

 WindowManager manager = ((WindowManager) getApplicationContext()
                .getSystemService(Context.WINDOW_SERVICE));

 WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
 localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
 localLayoutParams.gravity = Gravity.TOP;
 localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|

 // this is to enable the notification to receive touch events
 WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |

 // Draws over status bar
 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

 localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
 localLayoutParams.height = (int) (50 * getResources()
                .getDisplayMetrics().scaledDensity);
 localLayoutParams.format = PixelFormat.TRANSPARENT;

 customViewGroup view = new customViewGroup(this);
 manager.addView(view, localLayoutParams);
Run Code Online (Sandbox Code Playgroud)

customViewGroup类

class customViewGroup extends ViewGroup {

    public customViewGroup(Context context) {
        super(context);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 8

对于4.1或更高版本的隐藏状态栏使用

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();
Run Code Online (Sandbox Code Playgroud)

要么

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
Run Code Online (Sandbox Code Playgroud)

使状态栏可见

View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
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.show();
Run Code Online (Sandbox Code Playgroud)

要么

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 
Run Code Online (Sandbox Code Playgroud)

参考Immersve View

android从全屏模式退出