昨天研究了一下自定义Dialog的弹框,其实要点都是把自定义好的view用setContentView(view)的方法设置进dialog里,首先我们先看一个简单的自定义Dialog。
一、写布局文件:custom_dialog_layout.xml(这个布局就是一个简单的提示内容,下面有一个确定的按钮,请参看评论中的效果图)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/content_layout"
android:layout_gravity="center"
android:gravity="center">
<LinearLayout
android:background="@drawable/dialog_content_white_with_radius"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/dialog_content_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="info"
android:textSize="@dimen/size40"
android:textColor="@color/word_color_444444"
android:padding="10dp"
android:gravity="center"/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/divide_line"/>