效果:
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使用就可以了