DialogFragment 圆角背景实现

效果:
这里写图片描述
1.在dialogFragment中动态设置背景色为透明色,注意在xml布局文件中设置并不会起作用。
2.定义布局圆角shape
3.在xml中以 android:background的方式引入。

/**
*DialogFragment 
*/
 @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    //设置背景透明
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        View inflate = inflater.inflate(R.layout.dialog_fragment_phone_call, container, false);

             return inflate;
    }

DialogFragment xml布局文件中

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg_phone_call"
        android:orientation="vertical">

shape定义

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <!-- 填充 -->
    <solid android:color="@color/white_color"/>
    <!-- 圆角 -->
    <corners
        android:radius="12dp"
        />
    <padding
        android:bottom="6dp"
        android:top="20dp"/>
</shape>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值