效果:
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>