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 ...
随机推荐
- 避免调试代码导致IE出错
记录一下 if(!window.console){ var names = ["log", "debug", "info", "w ...
- 微信小程序开发初探
一.关于微信小程序 1.1 小程序诞生的背景 张小龙说道: (1)一切以用户价值为依归→用户是微信的核心,所以微信中没有很多与客户无关的功能,比如QQ中的乱七八糟一系列东西. (2)让创造发挥价值→所 ...
- 检验你的前端基础——Sit the test
前端小学生向大家推荐一个网站:Sit the test.如果你是一名前端工程师或者立志于此,不妨试试此网站上面的测验题. 发现 十几天前,我在奇舞周刊的一篇文章中,发现了一个国外的技能测试网站:Sit ...
- Storm介绍(二)
作者:Jack47 转载请保留作者和原文出处 欢迎关注我的微信公众账号程序员杰克,两边的文章会同步,也可以添加我的RSS订阅源. 本文是Storm系列之一,主要介绍Storm的架构设计,推荐读者在阅读 ...
- hibernate一对一主键双向关联
关联是类(类的实例)之间的关系,表示有意义和值得关注的连接. 本系列将介绍Hibernate中主要的几种关联映射 Hibernate一对一主键单向关联Hibernate一对一主键双向关联Hiberna ...
- Android 浏览器 —— 使用 WebView 实现文件下载
对当前的WebView设置下载监听 mCurrentWebView.setDownloadListener(new DownloadListener() { @Override public void ...
- Redis系列之key操作命令与Redis中的事务详解(六)
序言 本篇主要目的有二: 1.展示所有数据类型中key的所有操作命令,以供大家学习,查阅,更深入的挖掘redis潜力. 2.掌握redis中的事务,让你的数据完整性一致性拥有更优的保障. redis命 ...
- 【.net 深呼吸】EqualityComparer——自定义相等比较
自定义实现两个对象的相等比较,一种方案是重写Object类的Equals方法,很easy,如果相等返回true,不相等就返回false.不过,如果把自定义相等的比较用于泛型集,比如Dictionary ...
- 【Win 10 应用开发】三维变换
所谓三维变换,其实是在二维平面上产生三维的视觉效果.前面老周简单提了一下透视效果,如果透视效果不能满需求,那可以考虑用三维变换. UIElement类有一个属性叫Transform3D,它定义的类型为 ...
- Oracle逻辑迁移某业务用户及数据
1.确定基本信息 2.源数据库导出 3.目的数据库导入 4.逻辑迁移注意事项 1.确定基本信息 确定基本信息: 源数据库所在系统类型:________ 源数据库地址:__.__.__.__ 源数据库版 ...