对于一些特殊的dialog,我们想自定义一些特殊的样式。这时候假设使用dialog指定的一些功能。是无法实现我们的需求的,这时候就要自己去定制实现dialog了,如今这个样例是我从stackoverflow搜的,是定制dialog的基础,假设大家想定制其它样式。能够在这个基础上去自己改动,以下我贴出这个定制代码的源代码:

custom_dialog.xml:

  1. <?
  2. xml version="1.0" encoding="utf-8"?>
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="fill_parent"
  5. android:layout_height="80dp"
  6. android:background="#3E80B4"
  7. android:orientation="vertical" >
  8. <TextView
  9. android:id="@+id/txt_dia"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:layout_gravity="center"
  13. android:layout_margin="10dp"
  14. android:text="Do you realy want to exit ?
  15. "
  16. android:textColor="@android:color/white"
  17. android:textSize="15dp"
  18. android:textStyle="bold"/>
  19. <LinearLayout
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. android:layout_gravity="center"
  23. android:background="#3E80B4"
  24. android:orientation="horizontal" >
  25. <Button
  26. android:id="@+id/btn_yes"
  27. android:layout_width="100dp"
  28. android:layout_height="30dp"
  29. android:background="@android:color/white"
  30. android:clickable="true"
  31. android:text="Yes"
  32. android:textColor="#5DBCD2"
  33. android:textStyle="bold" />
  34. <Button
  35. android:id="@+id/btn_no"
  36. android:layout_width="100dp"
  37. android:layout_height="30dp"
  38. android:layout_marginLeft="5dp"
  39. android:background="@android:color/white"
  40. android:clickable="true"
  41. android:text="No"
  42. android:textColor="#5DBCD2"
  43. android:textStyle="bold" />
  44. </LinearLayout>
  45. </LinearLayout>

CustomDialog.java:

  1. public class CustomDialogClass extends Dialog implements
  2. android.view.View.OnClickListener {
  3. public Activity c;
  4. public Dialog d;
  5. public Button yes, no;
  6. public CustomDialogClass(Activity a) {
  7. super(a);
  8. // TODO Auto-generated constructor stub
  9. this.c = a;
  10. }
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. requestWindowFeature(Window.FEATURE_NO_TITLE);
  15. setContentView(R.layout.custom_dialog);
  16. yes = (Button) findViewById(R.id.btn_yes);
  17. no = (Button) findViewById(R.id.btn_no);
  18. yes.setOnClickListener(this);
  19. no.setOnClickListener(this);
  20. }
  21. @Override
  22. public void onClick(View v) {
  23. switch (v.getId()) {
  24. case R.id.btn_yes:
  25. c.finish();
  26. break;
  27. case R.id.btn_no:
  28. dismiss();
  29. break;
  30. default:
  31. break;
  32. }
  33. dismiss();
  34. }
  35. }

调用自己定制的dialog:

  1. R.id.TXT_Exit:
  2. CustomDialogClass cdd=new CustomDialogClass(Values.this);
  3. cdd.show();

android定义dialog的更多相关文章

  1. Android自己定义dialog中的EditText无法弹出键盘的解决

    近期我独立开发的项目<全医会>已经在内測其中了.非常快将会上架到各大应用市场.之前开发的几个项目都由于一些原因没有上架还是比較遗憾的.所以,近期我心情格外的好. 今天在做一个新项目,专为律 ...

  2. 46.Android 自己定义Dialog

    46.Android 自己定义Dialog Android 自己定义Dialog 前言 提示Dialog 提示Dialog 效果图 菜单Dialog 菜单Dialog 效果图 DialogActivi ...

  3. android 自己定义dialog并实现失去焦点(背景透明)的功能

    前言:因为在项目中须要用到更新显示动画的需求,所以想到了dialog,自己定义dialog不难.网上教程非常多,可是在实现dialog背景透明的需求时,遇到了一点问题.网上的一些方法在我的机器上并没有 ...

  4. Android 对话框(Dialog)大全 建立你自己的对话框

    Android 对话框(Dialog)大全 建立你自己的对话框 原文地址: http://www.cnblogs.com/salam/archive/2010/11/15/1877512.html A ...

  5. Android自定义Dialog

    Android开发过程中,常常会遇到一些需求场景——在界面上弹出一个弹框,对用户进行提醒并让用户进行某些选择性的操作, 如退出登录时的弹窗,让用户选择“退出”还是“取消”等操作. Android系统提 ...

  6. Android中Dialog

    在Android中,Dialog是一个非常重要的UI, 它可以方便的给用户提示,用最简洁的方式向用户展示信息, 以下的图片是Dialog的一个整体架构,通过它,可以总体对Dialog有一个很清晰的认识 ...

  7. Android-它们的定义Dialog

    Android-它们的定义Dialog 2014年4月27日 星期天 天气晴朗 心情平静 本篇博文来分享一个也是开发中常常须要用到的功能-自己定义对话框,这里我用到了Android中的图形资源shap ...

  8. Android中Dialog的使用

    上一篇博文讲到对话框popWindow的使用,这篇博文主要解说Dialog的使用. 1.什么是Dialog? Dialog就是对话框的一种方式! 在Android开发中.我们常常会须要在Android ...

  9. 它们的定义dialog

    (1)你需要准备自己的自定义对话框样式,是一个布局文件 <?xml version="1.0" encoding="utf-8"? > <Li ...

随机推荐

  1. javat Itext实践 pdf

    1.简介 iText是著名的开放项目,是用于生成PDF文档的一个java类库.通过iText不仅可以生成PDF或rtf的文档,而且可以将XML.Html文件转化为PDF文件. 下载地址:https:/ ...

  2. PLSQL Developer连接远程Oracle方法(非安装client)

    远程连接Oracle比較麻烦,通常须要安装oracle的客户端才干实现. 通过instantclient能够比較简单的连接远程的Oracle. 1.新建文件夹D:\Oracle_Cleint用于存放相 ...

  3. android APK反编译及代码混淆

    反编译.查看源代码,需要用到两个工具:dex2jar 和 jdgui dex2jar(google code) jdgui(google code),最新版本请见 官方 操作很简单,步骤如下: 1.将 ...

  4. [React] Detect user activity with a custom useIdle React Hook

    If the user hasn't used your application for a few minutes, you may want to log them out of the appl ...

  5. 封装实现JavaScript 文件的动态载入功能

    function loadScript(url, callback){ var script = document.createElement ("script") script. ...

  6. spock spring 集成测试框架搭建心得

    转载:http://blog.csdn.net/hankle_xu/article/details/77531880 spock测试框架,使用groovy作为脚本语言,开发出的测试脚本具有优良的阅读性 ...

  7. Windows内存管理

    本博文很大程度上参考了,潘爱民先生的<Windows内核原理与实现>一书,在此对他表示感谢. 记得是在学C语言指针的时候,首次比较实际的使用内存寻址.也是在那个时候知道不能使用未初始化的指 ...

  8. thinkphp+Jquery MiniUI 开发 管理系统

    Jquery Miniui JS 兼容IE6+的浏览器,非常适合在企业内部使用. 管理系统等都非常方便. 在企业内部正在使用的是前期asp.net +fineui实现的管理系统.经过了几年的实践检验. ...

  9. 算法笔记_055:蓝桥杯练习 Tricky and Clever Password (Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 在年轻的时候,我们故事中的英雄——国王 Copa——他的私人数据并不是完全安全地隐蔽.对他来说是,这不可接受的.因此,他发明了一种密码,好 ...

  10. EAS常用工具类

    package com.kingdee.eas.custom; import java.io.File; import java.io.FileNotFoundException; import ja ...