本文实例讲述了android编程实现对话框的封装。分享给大家供大家参考,具体如下:
/*** 对话框*/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程序设计有所帮助。
新闻热点
疑难解答
图片精选