自定义进度条ProgressDIaLog

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);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值