美文网首页
Android dialog 背景全透明

Android dialog 背景全透明

作者: 冰楓紫憶 | 来源:发表于2021-12-01 11:29 被阅读0次
    public class BuyerInfoDialog extends Dialog implements View.OnClickListener {
      
        public BuyerInfoDialog(@NonNull Context context) {
            this(context, 0);
        }
    
        public BuyerInfoDialog(@NonNull Context context, int themeResId) {
            super(context, themeResId);
    
        }
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.layout_buyer_info);
            initView();
            Window window = this.getWindow();
            if (window != null) {
                //去除系统自带的margin
                window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                //设置dialog在界面中的属性
                window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
                //背景全透明
                window.setDimAmount(0f);
            }
    
        }
    }
    
    private BuyerInfoDialog buyerInfoDialog;
    if (buyerInfoDialog == null) {
                buyerInfoDialog = new BuyerInfoDialog(getContext(), R.style.Dialog_style);
            }
    
    <!--弹出框的样式-->
        <style name="Dialog_style" parent="android:Theme.Dialog">
            <item name="android:windowFrame">@null</item>
            <!-- 边框 -->
            <item name="android:windowIsFloating">true</item>
            <!-- 是否浮现在activity之上 -->
            <item name="android:windowIsTranslucent">false</item>
            <!-- 半透明 -->
            <item name="android:windowNoTitle">true</item>
            <!-- 无标题 -->
            <item name="android:windowBackground">@android:color/transparent</item>
            <!-- 背景透明 -->
            <item name="android:backgroundDimEnabled">true</item>
            <!-- 模糊 -->
        </style>
    

    相关文章

      网友评论

          本文标题:Android dialog 背景全透明

          本文链接:https://www.haomeiwen.com/subject/yvrsxrtx.html