bottomSheetDialogFragment全屏

编程入门 行业动态 更新时间:2024-10-25 14:30:03
本文介绍了bottomSheetDialogFragment全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

What I'm trying to achieve is something like Instagram in-app web browser, used when you click an ad:

我做了什么,是我使用了WebView bottomSheetDialogFragment,还是重写了 onCreateDialog 来获得全屏显示,如下所示:

what I did, is I used a WebView bottomSheetDialogFragment, and I override onCreateDialog to get the full screen like this :

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

这是我得到的结果:

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

my question is, how can I get the full screen effect, or how can achieve something like instagram browser?

ps:我尝试了第一个chrome自定义标签,但无法将其添加到对话框片段中.

ps: I tried first chrome custom tabs, but I couldn't add it inside dialog fragment.

谢谢.

推荐答案

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

In your custom BottomSheetDialogFragment you can use something like:

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

更多推荐

bottomSheetDialogFragment全屏

本文发布于:2023-07-11 12:26:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1094058.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:全屏   bottomSheetDialogFragment

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!