AlertDialog 透明全屏

来源:互联网 发布:网络胜利组漫画在线 编辑:程序博客网 时间:2024/05/17 23:13

在 drawable 下面建一个 xml 文件 

<style name="dialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <!--边框-->
        <item name="android:windowIsFloating">true</item>
        <!--是否浮现在activity之上-->
        <item name="android:windowIsTranslucent">true</item>
        <!--无标题-->
        <item name="android:windowBackground">@color/transparent</item>
        <!--背景透明-->
        <item name="android:backgroundDimEnabled">false</item>
        <!--模糊-->
        <item name="android:background">#00ffffff</item>
        <!-- 设置自定义布局的背景透明 -->
    </style>

代码

dialog = new AlertDialog.Builder(context, R.style.dialog).create();

        View view = LayoutInflater.from(context).inflate(R.layout.dialog, null);
        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
        dialog.getWindow().setContentView(view);
        dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
0 0
原创粉丝点击