gpt4 book ai didi

android - 在状态栏上使 bottomSheetDialog 全屏显示

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:36:03 35 4
gpt4 key购买 nike

我最近使用了 android.support.design.widget.BottomSheetDialogFragment。我想做一些类似于谷歌联系人应用程序的事情,它的 BottomSheet 可以覆盖工具栏和状态栏。但是,当我使用 BottomSheetDialogFragment 来实现它时,结果是这样的: My Implementation

如您所见, Activity 的工具栏仍然可见。这是我的 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可能会改变bottom sheet的样式,但我不知道如何改变它,我怀疑这是否有效。有人可以给我解决方案来实现它可以覆盖工具栏和状态栏吗?

最佳答案

试试这个。它对我有用。

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

关于android - 在状态栏上使 bottomSheetDialog 全屏显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36424964/

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