public class ProgressDIaLog extends Dialog{ private ProgressBar progressBar; private TextView tv_msg,tv_progress; public ProgressDIaLog(Context context) { //一开始就设置为透明背景 super(context, R.style.CustomDialog); init(context); } public void init(final Context context) { LayoutInflater inflater = LayoutInflater.from(context); //得到加载的view View v = inflater.inflate(R.layout.dialog_download_item, null); //加载布局 LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_download); progressBar = (ProgressBar) v.findViewById(R.id.progressBar_download); tv_msg = (TextView) v.findViewById(R.id._progress_textview); tv_progress = (TextView) v.findViewById(R.id.download_progress); //设置不可通过点击外面区域取消 setCanceledOnTouchOutside(false); setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { Toast.makeText(context,"加载取消",Toast.LENGTH_SHORT).show(); } }); // 设置布局,设为全屏 setContentView(layout, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); } // 设置加载信息 public void setMessage(String title,String msg){ tv_msg.setText(title); tv_progress.setText(msg); } //设置进度条 public void setProgressBar(ProgressBar progressBar) { this.progressBar = progressBar; } //获取进度条 public ProgressBar getProgressBar() { return progressBar; } //设置进度 public void setProgress(int progress){ tv_progress.setText(progress*100/progressBar.getMax() + "%"); progressBar.setProgress(progress); } }
自定义进度条ProgressDIaLog
最新推荐文章于 2021-05-25 15:47:09 发布