简体   繁体   English

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

[英]Modal Bottom Sheet shows navigation bar in full screen activities

I have implemented a Modal Bottom Sheet Fragment in a FullScreen Activity. 我在FullScreen活动中实现了模态底部片段片段。 The problem is that when I show the fragment, the navigation bar appears. 问题是,当我显示片段时,会出现导航栏。 Here is my code for showing the fragment: 这是我显示片段的代码:

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

And this is the 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;
    }

}

And finally, this is how I hide the toolbar and the navigation bar at the beginning of the activity: 最后,这就是我在活动开始时隐藏工具栏和导航栏的方法:

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);

Since the BottomSheetFragment creates dialog, It is rendered in a window different from the activity's window. 由于BottomSheetFragment创建了对话框,因此它会在与活动窗口不同的窗口中呈现。 So, you'll have to apply these systemUiVisibility flags to the dialog window too. 因此,您还必须将这些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;
                }
    }

Even in activity, set systemUiVisibility flags to window decorview instead of contentview 即使在活动中,也要将systemUiVisibility标志设置为window decorview而不是contentview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM