
效果图
自定义style
<style name="MyBottomDialogDStyle" parent="Theme.Design.BottomSheetDialog">
<item name="android:colorBackground">@android:color/transparent</item>
</style>
为啥设置的是colorBackground属性了 查看源码
<style name="Theme.Design.BottomSheetDialog" parent="Theme.AppCompat.Dialog">
在往下
<style name="Theme.AppCompat.Dialog" parent="Base.Theme.AppCompat.Dialog"/>
再往下
<style name="Base.Theme.AppCompat.Dialog" parent="Base.V7.Theme.AppCompat.Dialog"/>
再往下
<style name="Base.V7.Theme.AppCompat.Dialog" parent="Base.Theme.AppCompat">
<item name="android:colorBackground">?attr/colorBackgroundFloating</item>
<item name="android:colorBackgroundCacheHint">@null</item>
.......
</style>
注意属性值:
?attr/colorBackgroundFloating
<!-- Default color of background imagery for floating components, ex. dialogs, popups, and cards. -->
<attr format="color" name="colorBackgroundFloating"/>
英文注释翻译: “浮动组件的背景图像的默认颜色,例如。 对话框,弹出窗口和卡片” 这下你应该知道怎么处理了吧
xml布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/dp250"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp180"
android:layout_alignParentBottom="true"
android:background="@drawable/dialog_radius_shape">
</RelativeLayout>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:background="@android:color/transparent"
android:src="@drawable/ic_pkq_smile" />
</RelativeLayout>
代码:
private void showDeleteDialog(Long id) {
BottomSheetDialog sheetDialog = new BottomSheetDialog(mContext,R.style.MyBottomDialogDStyle);
sheetDialog.setContentView(R.layout.dialog_bottom_sheet_delete);
sheetDialog.show();
}
本文详细介绍了如何在Android中自定义BottomSheetDialog的样式,通过修改colorBackground属性实现透明背景效果,展示了从主题继承到具体属性设定的过程,并提供了XML布局和代码示例。

被折叠的 条评论
为什么被折叠?



