【转】【Android】ProgressDialog进度条对话框的使用
2013-11-29 08:35
441 查看
Android ProgressDialog进度条对话框的使用:
转自:http://aina-hk55hk.iteye.com/blog/679134/
Java代码
![](http://aina-hk55hk.iteye.com/images/icon_star.png)
<?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" />
<Button android:text="圆形进度条" android:id="@+id/Button01"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="长型进度条" android:id="@+id/Button02"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
Java代码
![](http://aina-hk55hk.iteye.com/images/icon_star.png)
package com.Aina.Android;
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 Test_ProgressDialog extends Activity {
/** Called when the activity is first created. */
private ProgressDialog mpDialog;
private Button btn1,btn2;
private int mCount = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1 = (Button) this.findViewById(R.id.Button01);
btn2 = (Button) this.findViewById(R.id.Button02);
btn1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
mpDialog = new ProgressDialog(Test_ProgressDialog.this);
mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条
mpDialog.setTitle("提示");//设置标题
mpDialog.setIcon(R.drawable.icon);//设置图标
mpDialog.setMessage("这是一个圆形进度条");
mpDialog.setIndeterminate(false);//设置进度条是否为不明确
mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消
mpDialog.setButton("确定", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
mpDialog.show();
}
});
btn2.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
mCount = 0;
mpDialog = new ProgressDialog(Test_ProgressDialog.this);
mpDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mpDialog.setTitle("提示");
mpDialog.setIcon(R.drawable.icon);
mpDialog.setMessage("这是一个长型进度条");
mpDialog.setMax(100);
mpDialog.setProgress(0);
mpDialog.setSecondaryProgress(50);
mpDialog.setIndeterminate(false);
mpDialog.setCancelable(true);
mpDialog.setButton("取消", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
new Thread(){
public void run(){
try{
while(mCount<=100){
mpDialog.setProgress(mCount++);
Thread.sleep(100);
}
mpDialog.cancel();
}catch(Exception ex){
mpDialog.cancel();
}
}
}.start();
mpDialog.show();
}
});
}
}
转自:http://aina-hk55hk.iteye.com/blog/679134/
Java代码
![](http://aina-hk55hk.iteye.com/images/icon_star.png)
<?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" />
<Button android:text="圆形进度条" android:id="@+id/Button01"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="长型进度条" android:id="@+id/Button02"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
Java代码
![](http://aina-hk55hk.iteye.com/images/icon_star.png)
package com.Aina.Android;
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 Test_ProgressDialog extends Activity {
/** Called when the activity is first created. */
private ProgressDialog mpDialog;
private Button btn1,btn2;
private int mCount = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1 = (Button) this.findViewById(R.id.Button01);
btn2 = (Button) this.findViewById(R.id.Button02);
btn1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
mpDialog = new ProgressDialog(Test_ProgressDialog.this);
mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条
mpDialog.setTitle("提示");//设置标题
mpDialog.setIcon(R.drawable.icon);//设置图标
mpDialog.setMessage("这是一个圆形进度条");
mpDialog.setIndeterminate(false);//设置进度条是否为不明确
mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消
mpDialog.setButton("确定", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
mpDialog.show();
}
});
btn2.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
mCount = 0;
mpDialog = new ProgressDialog(Test_ProgressDialog.this);
mpDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mpDialog.setTitle("提示");
mpDialog.setIcon(R.drawable.icon);
mpDialog.setMessage("这是一个长型进度条");
mpDialog.setMax(100);
mpDialog.setProgress(0);
mpDialog.setSecondaryProgress(50);
mpDialog.setIndeterminate(false);
mpDialog.setCancelable(true);
mpDialog.setButton("取消", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
new Thread(){
public void run(){
try{
while(mCount<=100){
mpDialog.setProgress(mCount++);
Thread.sleep(100);
}
mpDialog.cancel();
}catch(Exception ex){
mpDialog.cancel();
}
}
}.start();
mpDialog.show();
}
});
}
}
相关文章推荐
- Android带进度条对话框ProgressDialog的使用
- 【转】【Android】ProgressDialog进度条对话框的使用
- android开发步步为营之26:进度条对话框ProgressDialog的用法
- android 对话框中的进度条 (ProgressDialog)
- 第33章、进度条对话框ProgressDialog(从零开始学Android)
- Android 对话框中的进度条 (ProgressDialog)
- 2.14 ProgressDialog 进度条对话框的使用
- Android开发自学 -- 进度条对话框ProgressDialog
- Android 对话框中的进度条 ProgressDialog
- Android 对话框中的进度条 ProgressDialog
- android的progressDialog 的使用。android数据异步加载 对话框提示
- Android--ProgressBar(进度条)、ProgressDialog(进度条对话框)
- android dialog ——ProgressDialog 进度条对话框详解
- Android的ProgressDialog进度对话框的使用
- Android 进度条对话框ProgressDialog
- 实例详解Android自定义ProgressDialog进度条对话框的实现
- Android 对话框中的进度条 ProgressDialog
- 14_android进度条对话框的使用说明
- 【Android】进度条对话框ProgressDialog
- android当触碰屏幕时ProgressDialog进度条对话框就消失了的解决方法