使bottomSheetDialog全屏覆盖状态栏

我最近使用android.support.design.widget.BottomSheetDialogFragment。 我想做一些类似Google的联系人应用程序,它的BottomSheet可以覆盖工具栏和状态栏。 但是,当我使用BottomSheetDialogFragment来实现这一点,事实certificate这一点: 我的实施

正如你所看到的,活动的工具栏仍然可见。 这是我BottomSheetDialogFragment代码:

 public class KeyDetailFragment extends BottomSheetDialogFragment { private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() { @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { if (newState == BottomSheetBehavior.STATE_HIDDEN) { dismiss(); } } @Override public void onSlide(@NonNull View bottomSheet, float slideOffset) { } }; @Override public void setupDialog(Dialog dialog, int style) { super.setupDialog(dialog, style); View contentView = View.inflate(getActivity(), R.layout.sheet_key, null); dialog.setContentView(contentView); View parent = (View) contentView.getParent(); parent.setFitsSystemWindows(true); BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(parent); contentView.measure(0, 0); bottomSheetBehavior.setPeekHeight(contentView.getMeasuredHeight()); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) parent.getLayoutParams(); if (params.getBehavior() instanceof BottomSheetBehavior) { ((BottomSheetBehavior)params.getBehavior()).setBottomSheetCallback(mBottomSheetBehaviorCallback); } params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; parent.setLayoutParams(params); } } 

我提到的来源,我发现一个属性利益我:

 private static int getThemeResId(Context context, int themeId) { if (themeId == 0) { // If the provided theme is 0, then retrieve the dialogTheme from our theme TypedValue outValue = new TypedValue(); if (context.getTheme().resolveAttribute( R.attr.bottomSheetDialogTheme, outValue, true)) { themeId = outValue.resourceId; } else { // bottomSheetDialogTheme is not provided; we default to our light theme themeId = R.style.Theme_Design_Light_BottomSheetDialog; } } return themeId; } 

这里属性bottomSheetDialogTheme可能会改变底部表单的样式,但我不知道如何改变它,我怀疑这是否可行。 有人可以给我解决scheme,实现它可以覆盖工具栏和状态栏?

Solutions Collecting From Web of "使bottomSheetDialog全屏覆盖状态栏"

尝试这个。 这个对我有用。

 @Override public void setupDialog(Dialog dialog, int style) { super.setupDialog(dialog, style); View inflatedView = View.inflate(getContext(), R.layout.fragment_coupon, null); dialog.setContentView(inflatedView); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) inflatedView.getParent()).getLayoutParams(); CoordinatorLayout.Behavior behavior = params.getBehavior(); if (behavior != null && behavior instanceof BottomSheetBehavior) { ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback); } View parent = (View) inflatedView.getParent(); parent.setFitsSystemWindows(true); BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(parent); inflatedView.measure(0, 0); DisplayMetrics displaymetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int screenHeight = displaymetrics.heightPixels; bottomSheetBehavior.setPeekHeight(screenHeight); if (params.getBehavior() instanceof BottomSheetBehavior) { ((BottomSheetBehavior)params.getBehavior()).setBottomSheetCallback(mBottomSheetBehaviorCallback); } params.height = screenHeight; parent.setLayoutParams(params); } 

无法find解决这个问题的办法,但可以提出一个替代scheme,帮助我达到同样的目的。 以下是参考: http : //www.hidroh.com/2016/06/17/bottom-sheet-everything/

文章解释了创build一个底部活页,并添加背景阴影。