读书人

AlertDialog 运用 扩展

发布时间: 2012-06-26 10:04:13 作者: rapoo

AlertDialog 使用 扩展

AlertDialog

?

?

[功能]

也是一种Dialog

?

?

[原理]

1. AlertDialog 本身并没有构造函数 即 不可以通过 new AlertDialog(...) 来初始化 而只能通过 AlertDialog.Builder

2. 而 AlertDialog.Builder 比较像是AlertDialog的构造器 用于接收各种和 AlertDialog 有关的参数 然后通过 create() 来创建目标 AlertDialog

?

[代码 步骤]

1. 定义 AlertDialog.Builder 实例 并接受一些参数 如:图片 标题 正文

?AlertDialog 运用 扩展
    ?AlertDialog 运用 扩展
      ?AlertDialog 运用 扩展
        ?AlertDialog 运用 扩展
          ?AlertDialog 运用 扩展

            ?

            ?

            ?

            5. 以上所采用的都是AlertDialog 系统默认的布局 现在说自定义布局的情况 并添加一个用于取消AlertDialog 的 Button

            ?

            * 定义其布局 hello.main

            ?AlertDialog 运用 扩展

              ?

              ?

              * 通过LayoutInflater 得到上面 hello.xml 布局的 View view

              ?AlertDialog 运用 扩展
                ?AlertDialog 运用 扩展
                  ?AlertDialog 运用 扩展
                    ?AlertDialog 运用 扩展
                      ?AlertDialog 运用 扩展

读书人网 >移动开发

热点推荐