8

我有一个全屏活动,它使用以下两个功能隐藏/显示系统 UI:

// This snippet hides the system bars.
public static void hideSystemUI(View view) {
    // Set the IMMERSIVE flag.
    // Set the content to appear under the system bars so that the content
    // doesn't resize when the system bars hide and show.
    view.setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE);
}

// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
public static void showSystemUI(View view) {
    view.setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

由于当我显示 Snackbar 并显示系统 UI 时 UI 以全屏模式布局,因此它被绘制在导航栏的后面。我没有使用 aCoordinatorLayout并且目前没有理由使用它。鉴于系统 UI 的当前状态,让 Snackbar 显示在正确位置的正确方法是什么?

4

0 回答 0