【问题标题】:Bottom Sheet Dialog - Transparent background header with close button底部工作表对话框 - 带有关闭按钮的透明背景标题
【发布时间】:2021-09-27 16:53:00
【问题描述】:

我正在尝试为关闭按钮制作一个透明的背景标题。背景标题按预期工作,但是背景布局可以看到可见并且按钮也不清楚。

我正在尝试像下图这样构建

https://ibb.co/CVgrzjq

我的代码如下:

活动代码

final BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetMainStyle);
`dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
`dialog.show();

布局代码

<RelativeLayout 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="@android:color/transparent"
    android:gravity="center|top"
    android:orientation="vertical">


    <ImageView
        android:id="@+id/img_close"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:background="@android:color/transparent"
        android:clickable="true"
        android:forceDarkAllowed="false"
        android:paddingBottom="@dimen/dimen_8"
        android:src="@drawable/bottom_close"
        />


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="300dp"

        android:layout_below="@id/img_close"
        android:background="@drawable/rounded_dialog"
        app:background="@color/bkgcolor"
        android:orientation="vertical">

        <!-- All your required widgets here-->
    </RelativeLayout>
</RelativeLayout>

【问题讨论】:

    标签: android-studio android-layout android-bottomsheetdialog


    【解决方案1】:

    活动代码

    final BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.trans_bg_dialog);
    `dialog.show();
    

    将此添加到您的 style.xml 文件中

     <style name="trans_bg_dialog" parent="@style/Theme.AppCompat.Dialog">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
    </style>
    

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 2012-05-14
      • 1970-01-01
      • 2019-12-13
      • 2016-11-23
      • 2011-09-15
      • 2015-05-03
      • 1970-01-01
      • 2012-06-03
      相关资源
      最近更新 更多