android中的Dialog
一、Dialog概述
二、使用系统自带的Dialog
1、新建Builder
AlertDialog.Builder builder = new AlertDialog.Builder(StoryActivity.this);
dialog.show();
2、通过builder创建dialog
AlertDialog dialog = builder.setView(view).setTitle("查看评论").setNegativeButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create();
3、关于NegativeButton、PositiveButton、NeutralButton
早期版本,NegativeButton最右侧、PositiveButton最左侧、NeutralButton中间

在android4.0中,NegativeButton在最左侧、PositiveButton在最右侧

二、如何自定义Dialog
1、特别注意!!!(首先明确)
1.1 setContentView、setView与show()方法相对位置引起异常
如使用setContentView、setView方法来自定义View的话,须与show()方法保持先后顺序
dialog.show();
dialog.setContentView(contentView);
2.2 自定义Dilog之后,setTitle等方法无效
须自行在界面中添加
2、步骤同上
3、设置界面
使用以下方法实现自定义界面
setView(View view)
setView(View view, int viewSpacingLeft, int viewSpacingTop, int viewSpacingRight,int viewSpacingBottom)
setContentView(@LayoutRes int layoutResID)
setContentView(View view)
setContentView(View view, ViewGroup.LayoutParams params)//params Layout parameters for the view.
4、自定义Dialog的宽高
Window window = this.getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.height = dialogHeight;//设置你想要的宽高
window.setAttributes(params);
5、获得屏幕的宽高
DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高
d.heightPixels//取得px单位的值
d.xdpi//取得dp单位的值
android中的Dialog的更多相关文章
- Android中改变dialog的显示的位置和大小
private void setDialogSize(Dialog dg) { Window dialogWindow = dg.getWindow(); WindowManager.LayoutPa ...
- Android中控制Dialog呈现的时间
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/zinss26914/article/details/36900157 用线程控制dialog的呈现时 ...
- Android在Service中显示Dialog
在Service中弹出一个Dialog对话框 第1步:在应用的AndroidManifest.xml中需要添加权限.没有无法显示. <uses-permission android:name=& ...
- Android中自定义Activity和Dialog的位置大小背景和透明度等demo
1.自定义Activity显示样式 先在res/values下建colors.xml文件,写入: <?xml version="1.0" encoding="utf ...
- Android中Dialog
在Android中,Dialog是一个非常重要的UI, 它可以方便的给用户提示,用最简洁的方式向用户展示信息, 以下的图片是Dialog的一个整体架构,通过它,可以总体对Dialog有一个很清晰的认识 ...
- Android中制作自定义dialog对话框的实例
http://www.jb51.net/article/83319.htm 这篇文章主要介绍了Android中制作自定义dialog对话框的实例分享,安卓自带的Dialog显然不够用,因而我们要继 ...
- Android中自定义Activity和Dialog的位置大小背景和透明度等
1.自定义Activity显示样式 先在res/values下建colors.xml文件,写入: view plainprint? 1. <?xml version="1.0" ...
- 详细解读Android中的搜索框(二)—— Search Dialog
Search Dialog是提供搜索的控件之一,还有一个是上次小例子给出的searchView,关于SearchView的东西后面会说到.本次先从Search Dialog说起,让大家慢慢理解andr ...
- Android中Dialog对话框的调用及监听
Android中经常会需要在Android界面上弹出一些对话框提示用户,比如App的退出的时候都会有各种框来挽留你的心,支付宝的时候输入密码的密码框,非常常见及其实用的功能,类似于JS中的alter, ...
随机推荐
- 理解flex_对齐
容器属性: 左右对齐方式:justify-content:flex-start/flex-end/center/space-between/space-around; 上下对齐方式:align-ite ...
- loadrunner处理HTTP重定向请求
//place this in global.h int HttpRetCode; int i=0; char depthVal[10]; char cTransactName[2000 ...
- Netty 入门示例
服务端代码示例 import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.*; import io.netty.channe ...
- SpringRMI解析4-客户端实现
根据客户端配置文件,锁定入口类为RMIProxyFactoryBean,同样根据类的层次结构查找入口函数. <bean id="rmiServiceProxy" class= ...
- hdu2546 01背包
http://acm.split.hdu.edu.cn/showproblem.php?pid=2546 01背包问题,首先拿出5元买最贵的东西,那接下来就是背包容量m-5,物品数量n-1 的01背包 ...
- DOM--5 动态修改样式和层叠样式表
W3C DOM2 样式规范 CSSStyleSheet对象 表示所有css样式表,包括外部link和嵌入style的;通过document.styleSheets属性可以获得文档中CSSStyleSh ...
- BZOJ 1189 [HNOI2007]紧急疏散evacuate
Description 发生了火警,所有人员需要紧急疏散!假设每个房间是一个N M的矩形区域.每个格子如果是'.',那么表示这是一块空地:如果是'X',那么表示这是一面墙,如果是'D',那么表示这是一 ...
- 3、利用SuperObject 循环处理Json深层次的值
//遍历对象 procedure TForm1.Button5Click(Sender: TObject); var item,jo: ISuperObject; ja,JA_TYPE,JA_MAC: ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 1144. The Emperor's Riddle
1144. The Emperor's Riddle Time limit: 1.0 secondMemory limit: 4 MB Background In the olden times th ...