一、drawable文件下创建shape文件
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- rectangle表示为矩形 -->
<!-- 填充的颜色 -->
<solid android:color="@color/white" />
<!-- 边框的颜色和粗细 -->
<stroke
android:width="1dp"
android:color="@color/white" />
<!-- android:radius 关键点,圆角的半径 -->
<corners
android:radius="2dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp" />
</shape>
- 在设置圆角时,圆角半径的大小必须大于
1dp
,否则是没有圆角效果的。 - 如果你想单独设置某几个角是圆角, 你必须首先声明
radius
属性(必须大于1dp
), 然后在其他四个角的属性中设置每个角的实际想要的半径大小, 不想圆角的设置为0dp
。
将该drawable
文件设为你BottomSheetDialog
布局的背景即可。成功则无需第二步,如果发现圆角和背景重叠了则继续第二步。
二、设置BottomSheetDialog的背景为透明
style.xml
文件夹下添加下面两个style
<style name="BottomSheetDialog" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/bottomSheetStyleWrapper</item>
</style>
<style name="bottomSheetStyleWrapper" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@android:color/transparent</item>
</style>
- 初始化
BottomSheetDialog
的时候指定上面的style
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this,R.style.BottomSheetDialog);
bottomSheetDialog.setContentView(R.layout.bottom_sheet_dialog);
bottomSheetDialog.show();