你好,游客 登录 注册 搜索
背景:
阅读新闻

Android自定义弹窗进度条【附源码】

[日期:2013-03-29] 来源:Linux社区  作者:viviwen123 [字体:大 中 小]

myprogressbar.xml的内容如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/back_qian"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="正在切换状态...."
        android:textSize="18sp"
        android:textColor="@color/black" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="" />

<ProgressBar
    android:id="@+id/progressBar1"   
    style="@style/ProgressBar_Mini"
    android:layout_width="290dp"
    android:layout_height="17dp" />
 
</LinearLayout>

MyProgressBar.java的内容如下:

package com.wl.util;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;

import com.wl.R;

public class MyProgressBar {
 Dialog dialog;
 Context context;
 // 声明ProgressBar对象
 private ProgressBar pro1;
 

 /**
  * 构造
  */
 public MyProgressBar(Context context) {
  // TODO Auto-generated constructor stub
  this.context = context;
  dialog = new Dialog(context, R.style.dialog);
  dialog.setOnCancelListener(onCancelListener);
 }

 /**
  * 初始化进度对话框
  */
 public void initDialog() {

  LayoutInflater inflater = (LayoutInflater) context
    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View view = inflater.inflate(R.layout.myprogressbar, null);
  dialog.setContentView(view);
  pro1 = (ProgressBar) dialog.findViewById(R.id.progressBar1);
  // 设置进度条是否自动旋转,即设置其不确定模式,false表示不自动旋转
  pro1.setIndeterminate(false);
  // 设置ProgressBar的最大值
  pro1.setMax(100);

  // 设置ProgressBar的当前值
  pro1.setProgress(0);

 
  dialog.show();
 }

 public void setProgress(int progressValue) {
  pro1.setProgress(progressValue);
 }
 
 public void colseDialog() {
  dialog.dismiss();
 }

 public boolean isShowing() {
  if (dialog.isShowing()) {
   return true;
  } else {
   return false;
  }
 }

 OnCancelListener onCancelListener = new OnCancelListener() {
  @Override
  public void onCancel(DialogInterface dialog) {
   // TODO Auto-generated method stub
   dialog.dismiss();
  }
 };
}

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款