首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android BottomSheetDialogFragment在圆角后面有颜色。

Android BottomSheetDialogFragment在圆角后面有颜色。
EN

Stack Overflow用户
提问于 2019-01-08 21:57:33
回答 3查看 5.9K关注 0票数 8

我正在使用BottomSheetDialogFragment,我在右上角/左上角圆角,它工作正常,但我注意到在圆角后面,它是不透明的,这非常恼人。

在下面的截图中很明显:

我如何使它们变得透明?

EN

回答 3

Stack Overflow用户

发布于 2019-06-30 16:17:37

创建如下所示的自定义样式。

代码语言:javascript
运行
复制
 <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_corner_top_only</item>
    </style>

然后在自定义片段中覆盖此方法。

代码语言:javascript
运行
复制
 @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //bottom sheet round corners can be obtained but the while background appears to remove that we need to add this.
        setStyle(DialogFragment.STYLE_NO_FRAME,R.style.AppBottomSheetDialogTheme);
    }

这是与我一起工作,希望它将与您工作。

票数 23
EN

Stack Overflow用户

发布于 2019-04-10 03:02:59

您必须更改bottom sheet theme才能实现顶部圆形布局

创建自定义可绘制background_bottom_sheet_dialog_fragment.xml:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle">
    <corners
       android:topLeftRadius="8dp"
        android:topRightRadius="8dp" />
    <padding android:top="0dp" />
    <solid android:color="@color/white" />
</shape>

然后使用可绘制的作为背景覆盖styles.xml上的bottomSheetDialogTheme:

代码语言:javascript
运行
复制
<!--Bottom sheet-->
<style name="BottomSheet" parent="@style/Widget.Design.BottomSheet.Modal">
    <item 
    name="android:background">@drawable/background_bottom_sheet_dialog_fragment
    </item>
</style>

<style name="BaseBottomSheetDialog" 
    parent="@style/Theme.Design.Light.BottomSheetDialog">
    <item name="android:windowIsFloating">false</item>
    <item name="bottomSheetStyle">@style/BottomSheet</item>
</style>

<style name="BottomSheetDialogTheme" parent="BaseBottomSheetDialog" />

这将更改底部工作表的背景布局

注意:删除底部工作表对话框视图布局中的所有背景

票数 0
EN

Stack Overflow用户

发布于 2020-04-23 14:43:22

在你的BottomSheetDialogFragment中覆盖它

代码语言:javascript
运行
复制
@Override
public void setupDialog(Dialog dialog, int style) {
    View view = View.inflate(getContext(), R.layout.YOUR_LAYOUT, null);
    dialog.setContentView(view);
    ((View) view.getParent()).setBackgroundColor(getResources().getColor(android.R.color.transparent));
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54093393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档