当前位置: 首页 > news >正文

上海专业网站建设黄浦网站设计

上海专业网站建设,黄浦网站设计,展厅设计包括哪些内容,表格网站怎么做的当Android开发处理错误信息时#xff0c;经常会以Dialog的形式显示错误信息#xff0c;但是每次都new一个Dialog#xff0c;很麻烦#xff0c;也增加程序的开销#xff0c;所以今天就分享一种自定义单例AlertDialogpublic class AlertDialog {private static AlertDialog …当Android开发处理错误信息时经常会以Dialog的形式显示错误信息但是每次都new一个Dialog很麻烦也增加程序的开销所以今天就分享一种自定义单例AlertDialogpublic class AlertDialog {private static AlertDialog alertDialog null;private Context context;private Dialog dialog;private LinearLayout lLayout_bg;private TextView txt_title;private TextView txt_msg;private Button btn_neg;private Button btn_pos;private ImageView img_line;private Display display;private boolean showTitle false;private boolean showMsg false;private boolean showPosBtn false;private boolean showNegBtn false;public static AlertDialog getInstance(Context context){if (alertDialognull){synchronized (AlertDialog.class) {if (alertDialog null) {alertDialog new AlertDialog(context).builder();}}}return alertDialog;}public AlertDialog(Context context) {this.context context;WindowManager windowManager (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);display windowManager.getDefaultDisplay();}public AlertDialog builder() {// 获取Dialog布局View view LayoutInflater.from(context).inflate(R.layout.view_alertdialog, null);// 获取自定义Dialog布局中的控件lLayout_bg (LinearLayout) view.findViewById(R.id.lLayout_bg);txt_title (TextView) view.findViewById(R.id.txt_title);txt_title.setVisibility(View.GONE);txt_msg (TextView) view.findViewById(R.id.txt_msg);txt_msg.setVisibility(View.GONE);btn_neg (Button) view.findViewById(R.id.btn_neg);btn_neg.setVisibility(View.GONE);btn_pos (Button) view.findViewById(R.id.btn_pos);btn_pos.setVisibility(View.GONE);img_line (ImageView) view.findViewById(R.id.img_line);img_line.setVisibility(View.GONE);// 定义Dialog布局和参数dialog new Dialog(context, R.style.AlertDialogStyle);dialog.setContentView(view);// 调整dialog背景大小lLayout_bg.setLayoutParams(new FrameLayout.LayoutParams((int) (display.getWidth() * 0.85), LayoutParams.WRAP_CONTENT));return this;}public AlertDialog setTitle(String title) {showTitle true;if (.equals(title)) {txt_title.setText(标题);} else {txt_title.setText(title);}return this;}public AlertDialog setMsg(String msg) {showMsg true;if (.equals(msg)) {txt_msg.setText(内容);} else {txt_msg.setText(msg);}return this;}public AlertDialog setMsg(int rId) {showMsg true;txt_msg.setText(rId);return this;}public AlertDialog setCancelable(boolean cancel) {dialog.setCancelable(cancel);return this;}public AlertDialog setPositiveButton(String text,final OnClickListener listener) {showPosBtn true;if (.equals(text)) {btn_pos.setText(确定);} else {btn_pos.setText(text);}btn_pos.setOnClickListener(new OnClickListener() {Overridepublic void onClick(View v) {if(listener!null) {listener.onClick(v);}dialog.dismiss();}});return this;}public AlertDialog setNegativeButton(String text,final OnClickListener listener) {showNegBtn true;if (.equals(text)) {btn_neg.setText(取消);} else {btn_neg.setText(text);}btn_neg.setOnClickListener(new OnClickListener() {Overridepublic void onClick(View v) {if(listener!null) {listener.onClick(v);}dialog.dismiss();}});return this;}private void setLayout() {if (!showTitle !showMsg) {txt_title.setText();txt_title.setVisibility(View.VISIBLE);}if (showTitle) {txt_title.setVisibility(View.VISIBLE);}if (showMsg) {txt_msg.setVisibility(View.VISIBLE);}if (!showPosBtn !showNegBtn) {btn_pos.setText(确定);btn_pos.setVisibility(View.VISIBLE);btn_pos.setBackgroundResource(R.drawable.alertdialog_single_selector);btn_pos.setOnClickListener(new OnClickListener() {Overridepublic void onClick(View v) {dialog.dismiss();}});}if (showPosBtn showNegBtn) {btn_pos.setVisibility(View.VISIBLE);btn_pos.setBackgroundResource(R.drawable.alertdialog_right_selector);btn_neg.setVisibility(View.VISIBLE);btn_neg.setBackgroundResource(R.drawable.alertdialog_left_selector);img_line.setVisibility(View.VISIBLE);}if (showPosBtn !showNegBtn) {btn_pos.setVisibility(View.VISIBLE);btn_pos.setBackgroundResource(R.drawable.alertdialog_single_selector);}if (!showPosBtn showNegBtn) {btn_neg.setVisibility(View.VISIBLE);btn_neg.setBackgroundResource(R.drawable.alertdialog_single_selector);}}public void show() {setLayout();dialog.show();}}布局文件view_alertdialog.xmlandroid:idid/lLayout_bgandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:backgrounddrawable/alert_bgandroid:orientationverticalandroid:idid/txt_titleandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginLeft15dpandroid:layout_marginRight15dpandroid:layout_marginTop15dpandroid:gravitycenterandroid:text提示android:textColorcolor/blackandroid:textSize18dp /android:idid/txt_msgandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginLeft15dpandroid:layout_marginRight15dpandroid:layout_marginTop10dpandroid:layout_marginBottom10dpandroid:gravitycenterandroid:text您确定要退出吗android:textColorcolor/blackandroid:textSize16dp /android:layout_widthmatch_parentandroid:layout_height0.5dpandroid:layout_marginTop10dpandroid:backgroundcolor/alertdialog_line /android:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationhorizontalandroid:idid/btn_negandroid:layout_widthwrap_contentandroid:layout_height43dpandroid:layout_weight1android:backgrounddrawable/alertdialog_left_selectorandroid:gravitycenterandroid:text确定android:textColorcolor/bigtextcolorandroid:textSize16sp /android:idid/img_lineandroid:layout_width0.5dpandroid:layout_height43dpandroid:backgroundcolor/alertdialog_line /android:idid/btn_posandroid:layout_widthwrap_contentandroid:layout_height43dpandroid:layout_weight1android:backgrounddrawable/alertdialog_right_selectorandroid:gravitycenterandroid:text取消android:textColorcolor/themecolorandroid:textSize16sp /效果显示以上就是本文的全部内容希望对大家的学习有所帮助也希望大家多多支持编程圈。
http://www.pierceye.com/news/797682/

相关文章:

  • 服装网站设计策划工业设计最吃香的专业
  • 东莞找公司网站ui界面设计说明范文
  • 淘宝网页版手机登录保定seo外包服务商
  • 网站开发 总结报告想给公司做网站怎么做
  • 思创医惠网站建设wordpress熊掌号号主页展现
  • 网站设置的参数新兴县城乡建设局网站登录
  • 网站未备案或已封禁六安城市网官网
  • 信息产业部网站备案系统建立一个网站的流程
  • 门户网站建站多少钱功能性质网站
  • 网站关键词是什么意思易网网站多少
  • 网站建设培训 上海网站建设公司有前途吗
  • 做普通网站选择什么服务器企业vi设计公司哪家好
  • 嘉兴本地推广网站如何查看网站是否开启gzip
  • 网站菜单导航制作教程畅言 wordpress插件
  • 太原网站建设联系方式免费创建网站教程
  • 有服务器自己怎么做网站深圳财务小公司网站
  • 装修装饰网站建设东莞环保公司
  • 网站开发大公司需要资格证吗申请域名免费
  • 建设维护网站未签订合同网站上线之前做哪些工作
  • dede 网站图标网站安装php
  • 网站管理更新维护湖南网站建设策划
  • 桥头东莞网站建设网站建设的开发方式和费用
  • 无锡网站优化哪家好wordpress会员内容
  • 网站需求分析的重要手机网站建设的规划
  • 国内大一html网站简单设计用那种语言做网站比较好
  • 网站的flash陕西煤化建设集团铜川分公司网站
  • 网站还能赚钱吗logo公司商标设计
  • 数字校园建设专题网站wordpress游览器标签页
  • 企业网站分析报告途牛网站大数据建设
  • 免费创建论坛网站wordpress sql插件