如何在BottomSheetDialog android的顶部中心添加关闭按钮?

如何在BottomSheetDialog android的顶部中心添加关闭按钮?,第1张

概述想要在BottomSheetDialog上添加关闭按钮以将其关闭.我正在为BottomSheetDialog使用自定义视图(线性布局).filterDialog=newBottomSheetDialog(context);filterDialog.setContentView(rootView);filterDialog.getWindow().setWindowAnimations(R.style.CustomDialogAnimation)

想要在BottomSheetDialog上添加关闭按钮以将其关闭.

我正在为BottomSheetDialog使用自定义视图(线性布局).

filterDialog = new BottomSheetDialog(context);
filterDialog.setContentVIEw(rootVIEw);
filterDialog.getwindow().setwindowAnimations(R.style.CustomDialogAnimation);
filterDialog.show();

下图是我的filterDialog:

这就是我想要实现的目标:

任何帮助将不胜感激.

解决方法:

我已经通过使用带有自定义(底部)动画的Dialog(全屏)解决了这个问题.

设计:

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:app="http://schemas.androID.com/apk/res-auto"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:background="@color/colortransparent"androID:orIEntation="vertical"><linearLayout    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:gravity="center"    >    <ImageVIEw        androID:ID="@+ID/img_close"        androID:layout_wIDth="@dimen/fifty_dp"        androID:layout_height="@dimen/thirty_dp"        androID:src="@drawable/ic_close_filter"/></linearLayout><linearLayout    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:background="@color/white"    androID:orIEntation="vertical"><!-- All your required Widgets here-->    </linearLayout> </linearLayout>

Java代码:

  Dialog filterDialog;    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());    // Get the layout inflater    LayoutInflater inflater = getActivity().getLayoutInflater();    VIEw rootVIEw = inflater.inflate(R.layout.dialog_filter, null);    final ImageVIEw close = (ImageVIEw) rootVIEw.findVIEwByID(R.ID.img_close);    builder.setVIEw(rootVIEw);    filterDialog = builder.create();    WindowManager.LayoutParams lp2 = new WindowManager.LayoutParams();    Window window = filterDialog.getwindow();    filterDialog.getwindow().setBackgroundDrawable(new colorDrawable(androID.graphics.color.transparent));    lp2.copyFrom(window.getAttributes());    //This makes the dialog take up the full wIDth    lp2.wIDth = VIEwGroup.LayoutParams.MATCH_PARENT;    lp2.height = VIEwGroup.LayoutParams.WRAP_CONTENT;    window.setAttributes(lp2);    Window dialogWindow = filterDialog.getwindow();    WindowManager.LayoutParams lp = dialogWindow.getAttributes();    dialogWindow.setGravity(Gravity.BottOM );    filterDialog.getwindow().setwindowAnimations(R.style.CustomDialogAnimation);    filterDialog.show();
总结

以上是内存溢出为你收集整理的如何在BottomSheetDialog android的顶部中心添加关闭按钮?全部内容,希望文章能够帮你解决如何在BottomSheetDialog android的顶部中心添加关闭按钮?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1091925.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存