状态栏与片段/应用程序ConstraintLayout重叠

我正在为学生制作社交网络应用程序,但遇到了一个问题。截止日期是2天,这对我来说很紧急。基本上,我使用以下代码删除了导航栏和状态栏:

super.onCreate(savedInstanceState);

try {
    Objects.requireNonNull(this.getSupportActionBar()).hide();
} catch (NullPointerException e) {
    e.printStackTrace();
}

    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    Window w = getWindow();
    w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
            WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));

    setContentView(R.layout.activity_main_menu);

    decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
        @Override
        public void onSystemUiVisibilityChange(int visibility) {
            if (visibility == 0) {
                decorView.setSystemUiVisibility(hideSystemBars());
            }
        }
    });

方法:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        decorView.setSystemUiVisibility(hideSystemBars());
    }
}

private int hideSystemBars() {
    return View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
}

It removes them successfully and when swiped from the bottom or top, it brings them back and hides them after a second or 2. The only issue is that the status bar overlaps the search view as presented in the picture: The color is white so you can nearly see but it's there

附加帮助:搜索视图是搜索片段的一部分,而搜索片段是活动的一部分。

评论