创建自定义布局的AlertDialog

简介: 1、创建LayoutInflater  LayoutInflater li=LayoutInflater.from(this); 2、填充布局 View quakeDetailsView=li.inflate(R.

1、创建LayoutInflater

 LayoutInflater li=LayoutInflater.from(this);

2、填充布局

View quakeDetailsView=li.inflate(R.layout.quake_details, null);

3、创建AlertDialog

AlertDialog.Builder quakeDialog=new AlertDialog.Builder(this);

AlertDialog的构造函数都是protect的,android只提供了AlertDialog.Builder来构造AlertDialog

4、设置AlertDialog自定义视图

quakeDialog.setView(quakeDetailsView);

5、返回Dialog

quakeDialog.create();

    LayoutInflater li = LayoutInflater.from( this );
            
// 将R.layout.quake_details填充到Layout
            View quakeDetailsView = li.inflate(R.layout.quake_details,  null );
            
            
// 创建AlertDialog,AlertDialog只能通过AlertDialog.Builder创建
            AlertDialog.Builder quakeDialog = new  AlertDialog.Builder( this );
            
// 指定R.layout.quake_details为Dialog的View
            quakeDialog.setView(quakeDetailsView);
            
return  quakeDialog.create();

 

 

相关文章
|
9月前
|
XML Java Android开发
Android 对话框组件 AlertDialog 四种常用方法
Android 对话框组件 AlertDialog 四种常用方法
102 0
AlertDialog(对话框)详解
本节继续给大家带来是显示提示信息的第三个控件AlertDialog(对话框),同时它也是其他Dialog的的父类!比如ProgressDialog,TimePickerDialog等,而AlertDialog的父类是:Dialog!另外,不像前面学习的Toast和Notification,AlertDialog并不能直接new出来,如果你打开AlertDialog的源码,会发现构造方法是protected的,如果我们要创建AlertDialog的话,我们需要使用到该类中的一个静态内部类:public static class Builder,然后来调用AlertDialog里的相关方法,来对A
37 0
EditText与TextView的开发中的常用属性,打造完美布局
EditText与TextView的开发中的常用属性,打造完美布局
59 0
|
Android开发
Android弹窗二则: PopupWindow和AlertDialog
前言 弹窗是图形界面必备的一个模块, 回忆一下windows那些恶心爆了的错误弹窗吧, 把弹窗制作的更高效友好一点是非常必要的. 这里说两个常用的弹窗类, PopupWindow和AlertDialog.
1121 0
|
XML Android开发 数据格式
addroid 自定义布局
        Activity类部分代码: RelativeLayout rl = new RelativeLayout(this); //设置RelativeLayout布局的宽高 RelativeLayout.
675 0