先上效果图:
[img]

[/img]

[img]

[/img]

[img]

[/img]

main.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    ><TextView      android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:text="@string/hello"    /><Buttonandroid:id="@+id/Button01"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="圆形进度条"/><Buttonandroid:id="@+id/Button02"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="长形进度条"/></LinearLayout>


Activity01
package xiaohang.zhimeng;import android.app.Activity;import android.app.ProgressDialog;import android.content.DialogInterface;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class Activity01 extends Activity {private Button xhButton01, xhButton02;int xh_count = 0;// 声明进度条对话框ProgressDialog my_pDialog;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);// 得到按钮对象xhButton01 = (Button) findViewById(R.id.Button01);xhButton02 = (Button) findViewById(R.id.Button02);// 设置xhButton01的事件监听xhButton01.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// 创建ProgressDialog对象my_pDialog = new ProgressDialog(Activity01.this);// 设置进度条风格,风格为圆形,旋转的my_pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);// 设置ProgressDialog 标题my_pDialog.setTitle("提示");// 设置ProgressDialog提示信息my_pDialog.setMessage("这是一个圆形进度条对话框");// 设置ProgressDialog标题图标my_pDialog.setIcon(R.drawable.img1);// 设置ProgressDialog 的进度条是否不明确 false 就是不设置为不明确my_pDialog.setIndeterminate(false);// 设置ProgressDialog 是否可以按退回键取消my_pDialog.setCancelable(true);// 设置ProgressDialog 的一个Buttonmy_pDialog.setButton("确定", new Bt1DialogListener());// 让ProgressDialog显示my_pDialog.show();}});// 设置xhButton02的事件监听xhButton02.setOnClickListener(new Button.OnClickListener() {@Overridepublic void onClick(View v) {xh_count = 0;// 创建ProgressDialog对象my_pDialog = new ProgressDialog(Activity01.this);// 设置进度条风格,风格为圆形,旋转的my_pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);// 设置ProgressDialog 标题my_pDialog.setTitle("提示");// 设置ProgressDialog提示信息my_pDialog.setMessage("这是一个长形进度条对话框");// 设置ProgressDialog标题图标my_pDialog.setIcon(R.drawable.img2);// 设置ProgressDialog 的进度条是否不明确 false 就是不设置为不明确my_pDialog.setIndeterminate(false);// 设置ProgressDialog 进度条进度my_pDialog.setProgress(100);// 设置ProgressDialog 是否可以按退回键取消my_pDialog.setCancelable(true);// 让ProgressDialog显示my_pDialog.show();new Thread() {@Overridepublic void run() {try {while (xh_count <= 100) {// 由线程来控制进度my_pDialog.setProgress(xh_count++);Thread.sleep(100);}my_pDialog.cancel();} catch (Exception e) {my_pDialog.cancel();}}}.start();}});}// xhButton01的监听器类class Bt1DialogListener implements DialogInterface.OnClickListener {@Overridepublic void onClick(DialogInterface dialog, int which) {// 点击“确定”按钮取消对话框dialog.cancel();}}}

更多相关文章

  1. android之Tab选项卡控件
  2. android radiobutton选中字体颜色改变的方法
  3. 【Android】Vibrator(震动模式)设置长短震动
  4. Android模仿Buttonbar
  5. android 线程优先级设置方法
  6. Android动态添加TextView
  7. android 下载文件图片圆形进度条
  8. Android(安卓)访问权限许可大全
  9. Android实现登录对话框

随机推荐

  1. Ipsec *** 中 NAT 穿越技术
  2. 【女神节有奖征文】付出行动才有所回报!
  3. MPLS系列之二:MPLS *** 静态路由、RIP、EI
  4. .net项目开发经验
  5. MPLS系列之一:Multi Protocol Label Switc
  6. TCPIP卷一(12):EIGRP的负载均衡方式 And Rou
  7. TCPIP卷一(11):EIGRP的汇总、stub、leak-map
  8. 价值
  9. TCPIP卷一(9):EIGRP的数据包格式、TLV、 三
  10. 容器?