Dialog,PopWindow,Toast使用场景

本文详细介绍了Android中Material风格Dialog的8种常用类型,包括普通、列表、单选、多选、等待、进度条、编辑和自定义Dialog,并讨论了Dialog的回调函数。同时,对比了Dialog与PopupWindow在设置位置、宽高、动画和显示位置的差异,强调了PopupWindow的便捷性和使用技巧。
摘要由CSDN通过智能技术生成


Material 风格的 Dialog 的使用  http://www.jianshu.com/p/6caffdbcd5db



以下为:八种形式的Dialog

转载出处:http://www.cnblogs.com/gzdaijie/p/5222191.html

参考文章:http://www.oschina.net/question/54100_32486 其中常见的dialog对话框



Dialog的类型:

2.1 普通Dialog(图1与图2)

2.2 列表Dialog(图3)
2.3 单选Dialog(图4)
2.4 多选Dialog(图5)
2.5 等待Dialog(图6)
2.6 进度条Dialog(图7)

2.7 编辑Dialog(图8)

2.8 自定义Dialog(图9)-----------------(可在此处自定义加载进度的对话框,常见加载网络时弹得对话框)


  • Android提供了丰富的Dialog函数,本文介绍最常用的8种对话框的使用方法,包括普通(包含提示消息和按钮)、列表、单选、多选、等待、进度条、编辑、自定义等多种形式,将在第2部分介绍。
  • 有时,我们希望在对话框创建或关闭时完成一些特定的功能,这需要复写Dialog的create()show()dismiss()等方法,将在第3部分介绍。

2.1 普通Dialog(图1与图2)

  • 2个按钮
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
public  class  MainActivity extends  Activity {
 
     @Override
     protected  void  onCreate(Bundle savedInstanceState) {
         super .onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         Button buttonNormal = (Button) findViewById(R.id.button_normal);
         buttonNormal.setOnClickListener( new  View.OnClickListener() {
             @Override
             public  void  onClick(View v) {
                 showNormalDialog();
             }
         });
     }
     
     private  void  showNormalDialog(){
         /* @setIcon 设置对话框图标
          * @setTitle 设置对话框标题
          * @setMessage 设置对话框消息提示
          * setXXX方法返回Dialog对象,因此可以链式设置属性
          */
         final  AlertDialog.Builder normalDialog =
             new  AlertDialog.Builder(MainActivity. this );
         normalDialog.setIcon(R.drawable.icon_dialog);
         normalDialog.setTitle( "我是一个普通Dialog" )
         normalDialog.setMessage( "你要点击哪一个按钮呢?" );
         normalDialog.setPositiveButton( "确定" ,
             new  DialogInterface.OnClickListener() {
             @Override
             public  void  onClick(DialogInterface dialog, int  which) {
                 //...To-do
             }
         });
         normalDialog.setNegativeButton( "关闭" ,
             new  DialogInterface.OnClickListener() {
             @Override
             public  void  onClick(DialogInterface dialog, int  which) {
                 //...To-do
             }
         });
         // 显示
         normalDialog.show();
     }
}
  • 3个按钮
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* @setNeutralButton 设置中间的按钮
  * 若只需一个按钮,仅设置 setPositiveButton 即可
  */
private  void  showMultiBtnDialog(){
     AlertDialog.Builder normalDialog =
         new  AlertDialog.Builder(MainActivity. this );
     normalDialog.setIcon(R.drawable.icon_dialog);
     normalDialog.setTitle( "我是一个普通Dialog" ).setMessage( "你要点击哪一个按钮呢?" );
     normalDialog.setPositiveButton( "按钮1" ,
         new  DialogInterface.OnClickListener() {
         @Override
         public  void  onClick(DialogInterface dialog, int  which) {
             // ...To-do
         }
     });
     normalDialog.setNeutralButton( "按钮2" ,
         new  DialogInterface.OnClickListener() {
         @Override
         public  void  onClick(DialogInterface dialog, int 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值