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

纳赛尔·阿塔里(Naseer Attari)

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

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

filterDialog = new BottomSheetDialog(context); filterDialog.setContentView(rootView); filterDialog.getWindow().setWindowAnimations(R.style.CustomDialogAnimation); filterDialog.show();

下图是我的filterDialog:

在此处输入图片说明

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

在此处输入图片说明

任何帮助将不胜感激。

纳赛尔·阿塔里(Naseer Attari)

我已经通过使用带有自定义(底部)动画的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();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在UIPageViewController顶部添加按钮?

如何在GWT中添加关闭按钮

如何在LayerList android的中心添加图像

如何在菜单顶部(在material-ui中单击时,按钮菜单中第一项上方)添加标题和关闭按钮?

如何在BottomSheetDialog上使用视图绑定

如何在 android recyclerview 项目中添加自定义关闭按钮?

如何在部分关闭按钮上添加按钮?

如何在tkinter窗口顶部添加问号[?]按钮

如何在flutter的按钮顶部添加标签

如何在clrCheckbox顶部添加selectAll / deselectAll按钮?

如何在滚动视图顶部添加浮动操作按钮

如何在 R Shiny 中添加“返回页面顶部”按钮?

如何在jhipster中添加滚动顶部按钮?

如何在 Delphi FireMonkey 的 MapView 顶部添加可点击的按钮?

如何在MFC对话框中添加关闭按钮

如何在幻灯片上添加关闭按钮

如何在引导卡上添加关闭按钮?

如何在iFrame中添加原始的关闭按钮?

如何在按钮标签内添加数据关闭?

如何在 Swift 中添加按钮以关闭模式

如何在点击“添加”或“取消”按钮后关闭EKEventEditViewController

如何在Android中的G +登录按钮中心设置textview

如何在Android中对齐屏幕中心的按钮

如何使用网页上的关闭按钮创建顶部栏?

如何在BottomSheetDialog中的GridView中向上滚动?

如何在Android的LinearLayout中以编程方式在顶部中心绘制一个圆?

如何添加回或取消按钮以关闭UIDocumentBrowser

无法关闭BottomSheetDialog

如何在单选按钮系列的顶部添加简单的字符串?