gpt4 book ai didi

android - bottomSheetDialogFragment 全屏

转载 作者:行者123 更新时间:2023-12-03 07:30:58 25 4
gpt4 key购买 nike

我想要实现的是类似于 Instagram 应用内网络浏览器,在您点击广告时使用:

Instagram web browser

我所做的是,我使用了 WebView bottomSheetDialogFragment,并覆盖了 onCreateDialog像这样获得全屏:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
BottomSheetDialog bottomSheetDialog=(BottomSheetDialog)super.onCreateDialog(savedInstanceState);
bottomSheetDialog.setOnShowListener(dialog -> {
BottomSheetDialog dialogc = (BottomSheetDialog) dialog;
FrameLayout bottomSheet = dialogc .findViewById(android.support.design.R.id.design_bottom_sheet);
BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
//BottomSheetBehavior.from(bottomSheet).setSkipCollapsed(true);
//BottomSheetBehavior.from(bottomSheet).setHideable(true);
});
return bottomSheetDialog;
}

这是我得到的结果:

web browser

我的问题是,如何才能获得全屏效果,或者如何实现类似instagram浏览器的东西?

ps:我尝试了第一个 chrome 自定义标签,但我无法在对话框 fragment 中添加它。

谢谢你。

最佳答案

在您的自定义 BottomSheetDialogFragment 你可以使用类似的东西:

  @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override public void onShow(DialogInterface dialogInterface) {
BottomSheetDialog bottomSheetDialog = (BottomSheetDialog) dialogInterface;
setupFullHeight(bottomSheetDialog);
}
});
return dialog;
}


private void setupFullHeight(BottomSheetDialog bottomSheetDialog) {
FrameLayout bottomSheet = (FrameLayout) bottomSheetDialog.findViewById(R.id.design_bottom_sheet);
BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
ViewGroup.LayoutParams layoutParams = bottomSheet.getLayoutParams();

int windowHeight = getWindowHeight();
if (layoutParams != null) {
layoutParams.height = windowHeight;
}
bottomSheet.setLayoutParams(layoutParams);
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}

private int getWindowHeight() {
// Calculate window height for fullscreen use
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.heightPixels;
}

关于android - bottomSheetDialogFragment 全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58065771/

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