我们自己清楚,android的原生控件实在是不堪入目,在很多时候无法满足项目需求,所以在项目进行的过程中,我们很多时候就需要自定义控件,继承重写从而实现我们的需求。并且自定义控件将体现代码的复用,分层的架构学管理,妙用无穷。本文将详细介绍自定义Dialog的多种思路以及给出如何进行自定义控件的指南。
文章结构(两种思路实现):1.复用率不高的,而且在dialog进行的逻辑处理较多的情况下,建议使用将dialog封装成一个类,继承基本的Dialog类实现。(在这里的后面会详细说明自定义样式的问题喔!)2.复用率高,而且每个dialog都要求有固定的布局格式的话,建议使用一个BaseDialog类作为你实际实现dialog的父类
先上图:
这里写图片描述 就是这种仿谷歌风格的自定义dialog啦!!
一、第一种思路实现的详解:
首先当然是你想要的dialog布局,这里你自己想怎么折腾就怎么折腾随你。由于这里使用了radiobutton的多向运用,可在此不详细解析,欲想看明radiobutton的多向运用请看我的另一篇博客:Android之RadioButton和RadioGroup结合Dialog的多种运用详解
android:layout_width="360dp"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:orientation="horizontal">
android:id="@+id/icon_title"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="18dp"
android:gravity="center"
android:src="@drawable/setting" />
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="20dp"
android:gravity="center_vertical"
android:text="广播周期设定"
android:textSize="17sp" />
android:id="@+id/groupBroadcast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="18dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
android:id="@+id/rbtn_BroadcastClose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:checked="true"
android:drawableLeft="@drawable/settingbroadst_checked_style"
android:drawablePadding="20dp"
android:paddingLeft="18dp"
android:text="关闭"
android:textColor=