本文实例讲述了android编程实现对话框的封装。分享给大家供大家参考,具体如下:
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/** * 对话框 */ private static ProgressDialog mProgressDialog; /** * 默认的对话框 * 标题、内容、两个按钮 * @param context * @param title * @param content * @param btnOKStr 是空字符的话 该按钮不显示 (特别注意) * @param btnCancelStr 是空字符的话 该按钮不显示 * @param onClick */ public static void showDefaultDialog(Context context,String title,String content, String btnOKStr,String btnCancelStr,OnClickListener onClick){ showDefaultDialog(context, title, content, btnOKStr, btnCancelStr, onClick, null ); } /** * 默认的对话框 + cancel事件 * @param context * @param title * @param content * @param btnOKStr * @param btnCancelStr * @param onClick * @param onCancel */ public static void showDefaultDialog(Context context,String title,String content, String btnOKStr,String btnCancelStr, OnClickListener onClick,OnCancelListener onCancel){ AlertDialog.Builder mBuilder = new AlertDialog.Builder(context); if (title != null ){ mBuilder.setTitle(title); } mBuilder.setMessage(content); if (btnOKStr == null ) btnOKStr = "确定" ; if (btnCancelStr == null ) btnCancelStr = "取消" ; if (!btnOKStr.trim().equals( "" )) mBuilder.setPositiveButton(btnOKStr, onClick); if (!btnCancelStr.trim().equals( "" )) mBuilder.setNegativeButton(btnCancelStr, onClick); if (onCancel != null ){ mBuilder.setOnCancelListener(onCancel); } mBuilder.show(); } public static void showProgressDialog(Context context,String msg, boolean cancelable) { // dismissProgressDialog(); mProgressDialog = new ProgressDialog(context); mProgressDialog.setMessage(msg); mProgressDialog.setCancelable(cancelable); mProgressDialog.show(); } public static void dismissProgressDialog(){ if (mProgressDialog != null && mProgressDialog.isShowing()) { mProgressDialog.dismiss(); mProgressDialog = null ; } } |
希望本文所述对大家Android程序设计有所帮助。