gpt4 book ai didi

android - 模态 Bottom Sheet 在全屏 Activity 中显示导航栏

转载 作者:行者123 更新时间:2023-12-03 10:12:15 26 4
gpt4 key购买 nike

我已经在全屏 Activity 中实现了模态 Bottom Sheet 片段。问题是当我显示片段时,会出现导航栏。这是我显示片段的代码:

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

}

最后,这是我在 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);

最佳答案

由于BottomSheetFragment创建了对话框,因此它将在与 Activity 窗口不同的窗口中呈现。因此,您也必须将这些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;
}
}

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

关于android - 模态 Bottom Sheet 在全屏 Activity 中显示导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55317212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com