效果:

一、新建类CommomDialog 继承Dialog

public class CommomDialog extends Dialog implements View.OnClickListener{
private TextView contentTxt;
private TextView titleTxt;
private TextView submitTxt;
private TextView cancelTxt; private Context mContext;
private String content;
private OnCloseListener listener;
private String positiveName;
private String negativeName;
private String title; public CommomDialog(Context context) {
super(context);
this.mContext = context;
}
public CommomDialog(Context context, String content) {
super(context, R.style.dialog);
this.mContext = context;
this.content = content;
} public CommomDialog(Context context, int themeResId, String content) {
super(context, themeResId);
this.mContext = context;
this.content = content;
} public CommomDialog(Context context, int themeResId, String content, OnCloseListener listener) {
super(context, themeResId);
this.mContext = context;
this.content = content;
this.listener = listener;
} protected CommomDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
this.mContext = context;
} public CommomDialog setTitle(String title){
this.title = title;
return this;
} public CommomDialog setPositiveButton(String name){
this.positiveName = name;
return this;
} public CommomDialog setNegativeButton(String name){
this.negativeName = name;
return this;
} @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_commom);
setCanceledOnTouchOutside(false);
initView();
} private void initView(){
contentTxt = (TextView)findViewById(R.id.content);
titleTxt = (TextView)findViewById(R.id.title);
submitTxt = (TextView)findViewById(R.id.submit);
submitTxt.setOnClickListener(this);
cancelTxt = (TextView)findViewById(R.id.cancel);
cancelTxt.setOnClickListener(this); contentTxt.setText(content);
if(!TextUtils.isEmpty(positiveName)){
submitTxt.setText(positiveName);
} if(!TextUtils.isEmpty(negativeName)){
cancelTxt.setText(negativeName);
} if(!TextUtils.isEmpty(title)){
titleTxt.setText(title);
} } @Override
public void onClick(View v) {
switch (v.getId()){
case R.id.cancel:
if(listener != null){
listener.onClick(this, false);
}
this.dismiss();
break;
case R.id.submit:
if(listener != null){
listener.onClick(this, true);
}
break;
}
} public interface OnCloseListener{
void onClick(Dialog dialog, boolean confirm);
}
}

二、新建dialog_commom.xml布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_round_white"
android:orientation="vertical" > <TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="12dp"
android:layout_marginTop="12dp"
android:text="提示"
android:textSize="16sp"
android:textColor="@color/black"/> <TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center_horizontal"
android:lineSpacingExtra="3dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:layout_marginRight="40dp"
android:layout_marginBottom="30dp"
android:text="签到成功,获得200积分"
android:textSize="12sp"
android:textColor="@color/font_common_1"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/commom_background"/> <LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"> <TextView
android:id="@+id/cancel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_dialog_left_white"
android:layout_weight="1.0"
android:gravity="center"
android:text="取消"
android:textSize="12sp"
android:textColor="@color/font_common_2"/> <View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/commom_background"/> <TextView
android:id="@+id/submit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_dialog_right_white"
android:gravity="center"
android:layout_weight="1.0"
android:text="确定"
android:textSize="12sp"
android:textColor="@color/font_blue"/> </LinearLayout> </LinearLayout>

三、在drawable下新建三个xml

bg_dialog_left_white.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/white" />
<corners android:bottomLeftRadius="8dp" />
</shape>

bg_dialog_right_white.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/white" />
<corners android:bottomRightRadius="8dp" />
</shape>

bg_round_white.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/white" />
<corners android:radius="8dp" />
</shape>

四、在styles.xml添加

<style name="dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<!--边框-->
<item name="android:windowIsFloating">true</item>
<!--是否浮现在activity之上-->
<item name="android:windowIsTranslucent">false</item>
<!--半透明-->
<item name="android:windowNoTitle">true</item>
<!--无标题-->
<item name="android:windowBackground">@android:color/transparent</item>
<!--背景透明-->
<item name="android:backgroundDimEnabled">true</item>
<!--模糊--> </style>

五、在colors.xml中添加

 <color name="mainColor">#573567</color>
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
<color name="font_gray_b">#d4d4d3</color> <color name="font_tab_1">#42369a</color>
<color name="font_tab_0">#b1b1b1</color> <color name="font_common_1">#424242</color>
<color name="font_common_2">#a1a1a1</color>
<color name="font_blue">#42369a</color> <color name="font_green">#00cccc</color> <color name="commom_background">#f3f3f3</color>

六、触发

new CommomDialog(Home.this, R.style.dialog, "确认退出此程序?", new CommomDialog.OnCloseListener() {
@Override
public void onClick(Dialog dialog, boolean confirm) {
if (confirm) {
ActivityCollector.FinishAll();
dialog.dismiss();
}
}
}).setTitle("提示").show();

作者发布的源码:https://github.com/xiaoxiaoqingyi/mine-android-repository

自定义DialogAlert消息框的更多相关文章

  1. Vue 自定义全局消息框组件

    消息弹框组件,默认3秒后自动关闭,可设置info/success/warning/error类型 效果图: 文件目录: Message.vue <template> <transit ...

  2. WPF自定义控件与样式(13)-自定义窗体Window & 自适应内容大小消息框MessageBox

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: 自定义 ...

  3. 【转】WPF自定义控件与样式(13)-自定义窗体Window & 自适应内容大小消息框MessageBox

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等. 本文主要内容: 自定义Window窗体样式: 基于自定义窗体实现自定义MessageB ...

  4. 【C#】分享一个可携带附加消息的增强消息框MessageBoxEx

    --------------201507160917更新--------------- 无意中发现标准消息框在Windows7是有声音的,只是在Windows server 2008(R2)无声,而我 ...

  5. AloneJs.msgbox() —— 弹出消息框

    一.引用 <link href="https://cdn.suziyun.com/alonejs.min.css" rel="stylesheet" /& ...

  6. C#Winform使用扩展方法自定义富文本框(RichTextBox)字体颜色

    在利用C#开发Winform应用程序的时候,我们有可能使用RichTextBox来实现实时显示应用程序日志的功能,日志又分为:一般消息,警告提示 和错误等类别.为了更好地区分不同类型的日志,我们需要使 ...

  7. EasyUI Messager 消息框

    通过 $.messager.defaults 重写默认的 defaults. 消息框(messager)提供不同样式的消息框,包括警示(alert).确认(confirm).提示(prompt).进展 ...

  8. Delphi 7中的四种消息框

    Delphi中平常使用的消息框有四种形式,有ShowMessage.MessageDlg.Application.MessageBox.MessageBox.下面来深入了解下这四种形式的实现和使用.1 ...

  9. 【Web】一个非常简单的移动web消息框

    适用:h5+jquery,移动网页最佳 最近在写个简单的公众号页面,前端验证时有些信息要提示,很简单的需求实在不想找啥现成的轮子,又不至于用alert这么粗暴,遂写了个非常简单的消息框,效果如图: 特 ...

随机推荐

  1. Vuejs——v-on

    版权声明:出处http://blog.csdn.net/qq20004604   目录(?)[+]   资料来于官方文档: http://cn.vuejs.org/guide/events.html ...

  2. 快学Scala之继承

        ## 1. 继承 Scala语言通过 extends 关键字来继承类. 那么继承一个类有什么好处呢? 子类除了拥有继承自超类的方法和字段(即为val(常量), var(变量)所定义的), 还可 ...

  3. “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛题解&&源码【A,水,B,水,C,水,D,快速幂,E,优先队列,F,暴力,G,贪心+排序,H,STL乱搞,I,尼姆博弈,J,差分dp,K,二分+排序,L,矩阵快速幂,M,线段树区间更新+Lazy思想,N,超级快速幂+扩展欧里几德,O,BFS】

    黑白图像直方图 发布时间: 2017年7月9日 18:30   最后更新: 2017年7月10日 21:08   时间限制: 1000ms   内存限制: 128M 描述 在一个矩形的灰度图像上,每个 ...

  4. 业余草推荐18个Java开源免费的CMS系统

    1.InfoGlue infoglue是一个高级的.可扩展的.健壮的内容管理系统,完全用Java开发.重要的功能包括完全支持多语言,站点之间良好的重用,以及广泛的集成能力. 该项目主页:http:// ...

  5. Phpcms 前台页面实现分页

    phpcms开发就是模仿里面原有的方法进行扩展,前台要实现分页,就去找后台页面的分页实现. 如后台 扩展->后台操作日志,就有分页展示. 1.先去添加自己的分页方法(千万不要在原来的方法上修改, ...

  6. (转)log4j(三)——如何控制不同级别的日志信息的输出?

    一:测试环境与log4j(一)——为什么要使用log4j?一样,这里不再重述 1 老规矩,先来个栗子,然后再聊聊感受 package test.log4j.test3; import org.apac ...

  7. app耗电优化之四 使用AlarmManager对任务进行合理安排

    AlarmManager 是用来设定定时任务.即用来设定那个任务在什么时候开始执行.为什么和省电有关系?这个需要和AlarmManager的使用先说起.AlarmManager 实际上只起到一个定时发 ...

  8. Entity Framework Core 执行SQL语句和存储过程

    无论ORM有多么强大,总会出现一些特殊的情况,它无法满足我们的要求.在这篇文章中,我们介绍几种执行SQL的方法. 表结构 在具体内容开始之前,我们先简单说明一下要使用的表结构. public clas ...

  9. ZOJ - 3469 Food Delivery (区间dp)

    When we are focusing on solving problems, we usually prefer to stay in front of computers rather tha ...

  10. 分享 android 源码

    Android精选源码 UI框架 QSkinLoader换肤框架 一款优雅的中国风Android笔记源码 ListView.RecyclerView两种方式实现聊天界面 android仿滴滴时间选择控 ...