Android 硬菜之圆角Dialog显示自定义布局(无棱角)

    这几天很纳闷项目中要使用弹窗,但是 之前这个用过,但是没有做详细的笔记, 时间一久就忘了, 今天把这个问题有解决了. 开始使用的是alertdialog来显示自定义布局弹窗,但是有个问题, 就是当我给弹窗的布局设置shape圆角的时候整个弹窗会有自带的4个圆角,很不好, 货不多说,撸代码!

1.设置dialog的style

<style name="MyDialog" parent="@android:style/Theme.Dialog">

        <!-- 边框 -->
        <item name="android:windowFrame">@null</item>
        <!-- 是否浮现在activity之上 -->
        <item name="android:windowIsFloating">true</item>
        <!-- 无标题 -->
        <item name="android:windowNoTitle">true</item>
        <!-- 背景透明 -->
        <item name="android:windowBackground">@android:color/transparent</item>
        <!-- 模糊 -->
        <item name="android:windowContentOverlay">@null</item>
    </style>

2.弹窗中要显示的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@drawable/top" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@drawable/down" />

</LinearLayout>

3.activity中的代码

private void dialog() {
Dialog dialog = new Dialog(this,R.style.MyDialog);
View view = getLayoutInflater().inflate(R.layout.dialog_layout, null);
dialog.setContentView(view);
//设置弹窗宽高        dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.WRAP_CONTENT);
//也可以这写,获取屏幕宽度减去100,相当于弹窗左右两边间距各是50,利用适配,写死不好
//dialog.getWindow().setLayout(UiUtils.getScreenHeight(mActivity).get(0)-100,WindowMan//ager.LayoutParams.WRAP_CONTENT);
        dialog.show();

    }

效果图:
这里写图片描述

注意: 设置宽高这里一定要看好了, 不然弹窗不能完全显示出来;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值