模态底部工作表在全屏活动中显示导航栏

时间:2019-03-23 18:47:12

标签: android android-layout bottom-sheet

我已经在FullScreen活动中实现了模态底页片段。问题是当我显示片段时,会出现导航栏。这是我显示片段的代码:

OptionsFragment optionsFragment=OptionsFragment.newInstance();
optionsFragment.show(getSupportFragmentManager(),"options_fragment");

这是片段:

public class OptionsFragment extends BottomSheetDialogFragment {


    public OptionsFragment() {
    }

    public static OptionsFragment newInstance() {
        OptionsFragment fragment = new OptionsFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.options_layout,container,false);
        return view;
    }

}

最后,这就是我在活动开始时隐藏工具栏和导航栏的方式:

mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

1 个答案:

答案 0 :(得分:0)

自从BottomSheetFragment创建对话框以来,它在与活动窗口不同的窗口中呈现。因此,您也必须将这些systemUiVisibility标志应用于对话框窗口。

    public class OptionsFragment extends BottomSheetDialogFragment {

            //other overridden methods

            @Override
            public Dialog onCreateDialog(Bundle savedInstanceState) {
                    Dialog dialog = super.onCreateDialog(savedInstanceState); 

         dialog.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
                    return dialog;
                }
    }

即使在活动中,也将systemUiVisibility标志设置为window decorview而不是contentview