Android如何自定义dialog
package com.example.aqua.myapplicationtesthttp; import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView; /**
* Created by Aqua on 2015/12/15.
*/
public class PopUpView extends Dialog { public PopUpView(Context context) {
super(context);
} public PopUpView(Context context, int theme) {
super(context, theme);
} public static class Builder {
private Context context;
private String message;
private String positiveButtonText;
private DialogInterface.OnClickListener positiveButtonClickListener; public Builder(Context context) {
this.context = context;
} public Builder setMessage(String message) {
this.message = message;
return this;
} public Builder setPositiveButton(int positiveButtonText,
DialogInterface.OnClickListener listener) {
this.positiveButtonText = (String) context
.getText(positiveButtonText);
this.positiveButtonClickListener = listener;
return this;
} public Builder setPositiveButton(DialogInterface.OnClickListener listener) {
this.positiveButtonClickListener = listener;
return this;
} public PopUpView create() {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // instantiate the dialog with the custom Theme
final PopUpView dialog = new PopUpView(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
View layout = inflater.inflate(R.layout.popupview, null);
// ViewGroup.LayoutParams pp = new ViewGroup.LayoutParams(500,300);//使用此处修改Dialog的宽和高
ViewGroup.LayoutParams pp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
dialog.addContentView(layout, pp);
dialog.setCancelable(false);//使dialog不会消失 //修改Dialog的宽度和高度
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
lp.alpha = 0.7f;
lp.width = 500;
lp.height = 300;
window.setAttributes(lp); // set the confirm button
if (positiveButtonClickListener != null) {
((Button) layout.findViewById(R.id.btn))
.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
positiveButtonClickListener.onClick(dialog,
DialogInterface.BUTTON_POSITIVE);
}
});
} // set the content message
if (message != null) {
((TextView) layout.findViewById(R.id.msg)).setText(message);
} // dialog.setContentView(layout);切忌不需要这一句
return dialog;
} }
}
Android如何自定义dialog的更多相关文章
- Android创建自定义dialog方法详解-样式去掉阴影效果
在自定义组件时,从已有组件源码中会很大收获.就拿progressDialog来说 间接父类是dialog,想了解dialog继承结构可以去百度,或者 从构造器来说ProgressDial ...
- Android:自定义Dialog
自定义Dialog:显示SeekBar 效果图: 步骤: //SettingActivity.java button4.setOnClickListener(new View.OnClickListe ...
- Android学习自定义Dialog
Dialog是Android提供的各种对话框的基类,和上篇的DialogFragment类似.为什么还要介绍Dialog呢,因为DialogFragment只能运行在Android3.0以上的系统中. ...
- 【Android】自定义Dialog
先上图 main.xml主界面文件 <?xml version="1.0" encoding="utf-8"?><LinearLayout x ...
- Android开发之自定义Dialog简单实现
本文着重研究了自定义对话框,通过一下步骤即可清晰的理解原理,通过更改界面设置和style类型,可以应用在各种各样适合自己的App中. 首先来看一下效果图: 首先是activity的界面 点击了上述图片 ...
- Android—自定义Dialog
在 Android 日常的开发中,Dialog 使用是比较广泛的.无论是提示一个提示语,还是确认信息,还是有一定交互的(弹出验证码,输入账号密码登录等等)对话框. 而我们去看一下原生的对话框,虽然随着 ...
- Android自定义Dialog(美化界面)
前言:在做项目的时候,发现dialog界面太丑陋,从csdn上下载了一份自定义dialog的源码,在他的基础上对界面进行美化...有需要的朋友可以直接拿走 效果图如下: 主要代码: /** * 自定义 ...
- Android自定义Dialog及其布局
实际项目开发中默认的Dialog样式无法满足需求,需要自定义Dialog及其布局,并响应布局中控件的事件. 上效果图: 自定义Dialog,LogoutDialog: 要将自定义布局传入构造函数中, ...
- Android中自定义Activity和Dialog的位置大小背景和透明度等demo
1.自定义Activity显示样式 先在res/values下建colors.xml文件,写入: <?xml version="1.0" encoding="utf ...
随机推荐
- 一步步开发自己的博客 .NET版(4、文章发布功能)百度编辑器
前言 这次开发的博客主要功能或特点: 第一:可以兼容各终端,特别是手机端. 第二:到时会用到大量html5,炫啊. 第三:导入博客园的精华文章,并做分类.(不要封我) 第四:做个插件,任何网站上的技术 ...
- Flume1 初识Flume和虚拟机搭建Flume环境
前言: 工作中需要同步日志到hdfs,以前是找运维用rsync做同步,现在一般是用flume同步数据到hdfs.以前为了工作简单看个flume的一些东西,今天下午有时间自己利用虚拟机搭建了 ...
- 再见Windows C++
我3年多以前写过一个小工具,是用来检测Windows操作系统的版本及其所安装的.NET Framework版本的,我用它来排查由于缺乏运行环境支持所导致的程序无法运行的问题.这个工具是用Visual ...
- Java访问Hbase
1.kerberos验证 a.下载对应版本JCE(Java Cryptography Extension),解压拷贝local_policy.jar/US_export_policy.jar到$JAV ...
- jQuery? 回归JavaScript原生API
如今技术日新月异,各类框架库也是层次不穷.即便当年漫山红遍的JQuery(让开发者write less, do more,So Perfect!!)如今也有被替代的大势.但JS原生API写法依旧:并且 ...
- 搭建LNAMP环境(二)- 源码安装Nginx1.10
上一篇:搭建LNAMP环境(一)- 源码安装MySQL5.6 1.yum安装编译nginx需要的包 yum -y install pcre pcre-devel zlib zlib-devel ope ...
- PHP 高级编程(3/5) - 使用SPL(标准PHP库)实现观察者模式
SPL(标准PHP库 - Standard PHP Library)是PHP5面向对象功能中重要的部分.原文解释是这样的“The Standard PHP Library (SPL) is a col ...
- ios 开发需要看的书籍
1.吴航写的<iOS应用逆向工程 第2版> 2.<iOS 应用安全攻防实战> 3.
- 浅谈css的栅格布局
栅格布局想必大家都很了解,我们做页面开发的时候,往往对页面板式的要求很高,如何对各个区域的内容排版,并使之对齐是我们的一大难题.而栅格系统就是我们排版的利器,他支持自动对齐.自动计算边距.流式布局等优 ...
- SharePoint2013 显示网站菜单中设计管理器功能
当部署完SharePoint2013后,并创建了对应的网站集,就开始试图去按照企业VI(Visual Identity)来定制站点的布局.色彩.字体等等的页面元素.可是,在站点的设置菜单中,默认没有“ ...