Android圆角对话框Dialog

效果:

Dialog样式:

  <!--对话框样式-->
    <style name="mdialog" parent="Theme.AppCompat.Dialog">
        <!--背景透明-->
        <item name="android:windowBackground">@android:color/transparent</item>
        <!--没有标题-->
        <item name="android:windowNoTitle">true</item>
        <!--背景昏暗-->
        <item name="android:backgroundDimEnabled">true</item>
    </style>

布局文件:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/mdialog_bg">

    <!--对话框标题区域-->
    <RelativeLayout
        android:id="@+id/layout_title"
        android:layout_width="280dp"
        android:layout_height="100dp"
        android:gravity="center">

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/text_title"
            android:textColor="@color/black"/>

    </RelativeLayout>

    <View
        android:id="@+id/view"
        android:layout_width="280dp"
        android:layout_height="1dp"
        android:layout_below="@id/layout_title"
        android:layout_marginBottom="5dp"
        android:background="@color/grey"/>

    <!--对话框按钮-->
    <LinearLayout
        android:id="@+id/bottom"
        android:layout_width="280dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/view"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <!--取消按钮-->
        <Button
            android:id="@+id/btn_cancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@null"
            android:text="@string/text_cancel"
            android:textColor="@color/blue"
            android:textSize="18sp"/>

        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="@color/grey"/>

        <!--退出按钮-->
        <Button
            android:id="@+id/btn_exit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@null"
            android:text="@string/text_exit"
            android:textColor="@color/blue"
            android:textSize="18sp"/>
    </LinearLayout>

</RelativeLayout>

圆角背景:mdialog_bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <!--背景颜色-->
    <solid android:color="@color/white"/>

    <!--设置圆角的角度-->
    <corners android:radius="16dp"/>

</shape>

使用:

正常的dialog使用就可以了

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值