BottomSheetDialogFragment的圆角 [英] Round corner for BottomSheetDialogFragment
问题描述
我有一个自定义的BttomSheetDialogFragment,我想在底部视图的顶部有圆角
i have an custom BttomSheetDialogFragment and i want to have round corners in top of Bottom View
这是我的Custom类,它使我想从底部显示的布局更加夸张
this is my Custom class that inflating my layout that i want to appear from bottom
View mView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.charge_layout, container, false);
initChargeLayoutViews();
return mView;
}
我也有这个xml资源文件作为背景:
and also i have this xml resource file as background :
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners android:topRightRadius="35dp"
android:topLeftRadius="35dp"
/>
<solid android:color="@color/white"/>
<padding android:top="10dp"
android:bottom="10dp"
android:right="16dp"
android:left="16dp"/>
但是问题是,当我将此资源文件设置为布局的根元素的背景时,拐角仍未圆化
but the problem is, when i set this resource file as background of my Layout's root element , the corners still are not rounded
我不能使用下面的代码:
and i can't use below code :
this.getDialog().getWindow().setBackgroundDrawableResource(R.drawable.charge_layout_background);
因为它覆盖了BottomSheetDialog的默认默认背景,所以我的Bottom View上方没有任何半透明的灰色
cuz its override default background of BottomSheetDialog and there wont be any semi-transparent gray color above my Bottom View
推荐答案
创建自定义可绘制对象rounded_dialog.xml
:
Create a custom drawable rounded_dialog.xml
:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners android:topLeftRadius="16dp"
android:topRightRadius="16dp"/>
</shape>
然后使用可绘制对象作为背景在styles.xml
上覆盖bottomSheetDialogTheme
:
Then override bottomSheetDialogTheme
on styles.xml
using the drawable as background:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
</style>
<style name="AppBottomSheetDialogTheme"
parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/AppModalStyle</item>
</style>
<style name="AppModalStyle"
parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@drawable/rounded_dialog</item>
</style>
这将更改应用程序的所有BottomSheetDialogs.
This will change all the BottomSheetDialogs of your app.
这篇关于BottomSheetDialogFragment的圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!