-
首先将代码分享出来:customDialog
-
最近做开发感觉Android原生AlertDialog和我们的APP不太符合,所以考虑自定义Dialog来匹配风格。
-
我们先看下QQ下线通知的Dialog:
感觉很是漂亮,当然要仿造了。 -
首先了解下Android原生Dialog的模样:
* -
再来看看我最终实现的效果图:
-
怎么样,还不错吧,下面一起来仿造QQ下线通知:
下面开始:
-
笔者采用的方式是扩展Android原生Dialog类,写一个自己的布局,将这个布局加载进去,核心在于布局文件,代码不难,下面先看布局文件的代码:custom_dialog.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:background="@color/colorWhite" android:orientation="vertical"> <TextView android:id="@+id/dialog_title" android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginTop="15dp" android:gravity="center" android:text="@string/title" android:textColor="#202020" android:textSize="16sp" /> <LinearLayout android:id="@+id/dialog_content" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/dialog_message" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="4dp" android:layout_marginRight="4dp