progressdialog进度框_进度对话框 ProgressDialog 用法总结
ProgressDialog 继承自AlertDialog,AlertDialog继承自Dialog
public class ProgressDialog extends AlertDialog
ProgressDialog的创建方式有两种,一种是new ProgressDialog,一种是调用ProgressDialog的静态方法show()创建并显示,这种进度条只能是圆形条。
image
ProgressDialog dialog = ProgressDialog.show(this, "提示", "正在登陆中…", true, false, null);
常用方法
setProgressStyle:设置进度条风格,风格为圆形,旋转的。
setTitlt:设置标题
setMessage:设置提示信息;
setIcon:设置标题图标;
setIndeterminate:设置ProgressDialog 的进度条是否不明确;这个属性对于ProgressDailog默认的转轮模式没有实际意义,默认下设置为true,它仅仅对带有ProgressBar的Dialog有作用。修改这个属性为false后可以实时更新进度条的进度。
setCancelable:设置ProgressDialog 是否可以按返回键取消;
cancelListner:当前Dialog强制取消之后将会被执行,通常用来清理未完成的任务。
setButton:设置ProgressDialog 的一个Button(需要监听Button事件);
show:显示ProgressDialog。
cancel:删除progressdialog
dismiss: 删除progressdialog 作用和cancel相同
setMax(int)、getMax:设置最大进度条的值
setProgress(int)、getProgress:更新进度条,当然一般都需要Handler的结合来更新进度条
incrementProgressBy(int)增加进度条
setProgressDrawable:设置progress发生变化时的进度指示条的背景图
Mainactivity
public class MainActivity extends ListActivity {
private ProgressDialog dialog;
private AlertDialog alertDialog;
private ProgressDialogFragment dialogFragment;
private Handler mHandler = new Handler() {
@Override
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case 0:
dialog.cancel();// cancel和dismiss唯一的区别是,调用cancel方法会【回调】OnCancelListener
break;
case 1:
int progress = (Integer) msg.obj;
if (progress < 20) {
dialog.incrementProgressBy(5);// 增加进度条的进度
mHandler.sendMessageDelayed(Message.obtain(mHandler, 1, progress + 1), 150);
} else dialog.dismiss();
break;
case 2:
alertDialog.dismiss();
break;
case 3:
getFragmentManager().beginTransaction().remove(dialogFragment).commit();
break;
}
};
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] array = { "ProgressDialog.STYLE_SPINNER:不确定的圆形滚动条",//
"ProgressDialog.STYLE_HORIZONTAL:确定的水平滚动条", //
"通过AlertDialog实现不确定圆形滚动条效果,其View包含一个ProgressBar",//
"通过DialogFragment实现不确定圆形滚动条效果,其View包含一个ProgressBar", };
setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, new ArrayList(Arrays.asList(array))));
Fragment fragment = getFragmentManager().findFragmentByTag("ProgressDialogFragment");
//旋转屏幕后dialogFragment为空,但是findFragmentByTag的结果不为空,所以dialogFragment将永远不会消失
if (fragment != null) {
if (dialogFragment == null) Toast.makeText(MainActivity.this, "dialogFragment为空,findFragmentByTag不为空", Toast.LENGTH_SHORT).show();
getFragmentManager().beginTransaction().remove(fragment).commit();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mHandler != null) mHandler.removeCallbacksAndMessages(null);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
switch (position) {
case 0://旋转屏幕后直接消失
showPD();
mHandler.sendEmptyMessageDelayed(0, 3000);
break;
case 1://旋转屏幕后直接消失
showHorizontalPD();
mHandler.sendMessageDelayed(Message.obtain(mHandler, 1, 0), 150);
break;
case 2://旋转屏幕后直接消失
showAlertDialog();
mHandler.sendEmptyMessageDelayed(2, 3000);
break;
case 3://旋转屏幕后会重新创建
showDialogFragment();
mHandler.sendEmptyMessageDelayed(3, 3000);
break;
}
}
* //跟AlertDailog的样式一摸一样,还有一个圆形进度条!!!!!!!
private void showPD() {
dialog = new ProgressDialog(this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//转盘
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.setTitle("提示");
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Toast.makeText(MainActivity.this, "消失了", Toast.LENGTH_SHORT).show();
}
});
dialog.setMessage("正在加载,请稍后……");
dialog.show();
}
private void showHorizontalPD() {
dialog = new ProgressDialog(this);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(false);
dialog.setIcon(R.drawable.ic_launcher);//这里指的是标题左侧的图标。注意:如果没有设置title只设置Icon的话,是不会显示图标的
dialog.setTitle("提示");
dialog.setMax(100);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定…", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "确定", Toast.LENGTH_SHORT).show();
}
});
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "取消…", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_SHORT).show();
}
});
dialog.setMessage("正在加载,请稍后……");
dialog.show();
}
private void showAlertDialog() {
alertDialog = new AlertDialog.Builder(this).setView(R.layout.layout).create();
alertDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);//设置Dialog背景透明效果
alertDialog.show();
}
private void showDialogFragment() {
dialogFragment = ProgressDialogFragment.newInstance("加载中…");
dialogFragment.show(getFragmentManager(), "ProgressDialogFragment");
}
}
ProgressDialogFragment
public class ProgressDialogFragment extends DialogFragment {
/**构造时把传入的参数带进来,注意一定要通过Bundle及setArguments传递数据*/
public static ProgressDialogFragment newInstance(String message) {
Bundle bundle = new Bundle();//把所有需要传递的数据都放在Bundle中
bundle.putString("message", message);
ProgressDialogFragment dialog = new ProgressDialogFragment();
dialog.setArguments(bundle);//通过setArguments把Bundle传递过去
return dialog;
}
@SuppressLint("InflateParams")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View contentView = getActivity().getLayoutInflater().inflate(R.layout.layout, null);
TextView tv_messag = (TextView) contentView.findViewById(R.id.tv_messag);
if (getArguments() != null && !TextUtils.isEmpty(getArguments().getString("message"))) {
tv_messag.setVisibility(View.VISIBLE);
tv_messag.setText(getArguments().getString("message"));
} else tv_messag.setVisibility(View.GONE);
Dialog dialog = new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//设置Dialog没有标题。需在setContentView之前设置,在之后设置会报错
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);//设置Dialog背景透明效果
dialog.setCancelable(false);
dialog.setContentView(contentView);
return dialog;
}
}
@希望能帮助到大家!
progressdialog进度框_进度对话框 ProgressDialog 用法总结相关推荐
- progressdialog进度框_使用ProgressDialog创建进度对话框
ProgressDialog代表了进度对话框,程序只要创建ProgressDialog实例,并将它显示出来就是一个进度对画框.使用ProgressDialog创建进度对话框有如下两种方式. ①如果只是 ...
- progressdialog进度框_ProgressDialog进度对话框
ProgressDialog是AlertDialog类的一个扩展,可以为一个未定义进度的任务显示一个旋转轮形状的进度动画,或者为一个指定进度的任务显示一个进度条. 一个对话框中显示一个进步指标和一个可 ...
- progressdialog进度框_ProgressDialog(进度弹窗)用法
1.实例化ProgressDialog //实例化ProgressDialog final ProgressDialog progressDialog = new ProgressDialog(Mai ...
- bash给脚本加进度条_进度条——shell脚本实现
进度条在以后开发,测试,运维中,可实现自动化检查项目的更新.运行等情况,大大加快工作效率. 1.代码实现1 #!/bin/bash 2 function proc() 3 { 4 count= ...
- java 线程 进度条_进度条与多线程
为什么需要进度条? 这里有200个左右的文件,每个文件里面有1000条数据库插入语句,总共约200 000条记录. 在单线程情况下,执行插入时界面会失去响应,完成插入需要长达8个小时. 不会有人认为界 ...
- java 进度条_进度条Java
你必须使用线程.设计一个实现Runnable接口的类,它将更新这样的值. class ProgressBarUpdator implements java.lang.Runnable { /** * ...
- Acitivity(页面)之间的跳转,ProgressBar 进度条,PopupWindow 弹出框,Dialog 对话框,Spinner下拉框
Acitivity(页面)之间的跳转 Acitivity(页面)之间的跳转需要使用到 Intent(意图) Intent intent = new Intent(MainActivity.this(从 ...
- word打开老是配置进度_小白教程 | office出现配置进度框,怎么办?
最近很多同学在备考二级时候,自己的电脑上office软件Word或者Excel出问题了,每次打开都会出现配置进度框. 这种情况怎么办呢? 这种情况都是注册表的问题,马上安排解决 之前在 右键菜单没有 ...
- 进度条上的起伏_进度条(ProgressBar)的功能与用法
进度条也是UI界面中一种非常实用的组件,通常用于向用户显示某个耗时操作完成的的百分比.进度条可以动态的显示进度,因此避免长时间的执行某个耗时的操作,让用户感觉程序失去了响应,从而更好的提高用户界面的友 ...
最新文章
- 反汇编算法介绍和应用——递归下降算法分析
- 用 C 语言实现面向对象编程
- 浅谈:Android应用清理内存
- c++编写托管dll_教程:如何编写简单的网站并免费托管
- 服务器怎么禁止iis静态文件,如何禁止IIS缓存静态文件
- 解决鼠标滚动的时候多次执行函数
- 85. Maximal Rectangle
- Shell脚本:Linux下定时备份MySQL数据库
- 如何解决联通电信宽带连接错误691
- Python 标准库 —— string
- 自动化运维--python_自动化-设计师的朋友还是敌人?
- 华为vrrp默认优先级_VRRP双主,真是要了我老命了
- 【web素材】02-10款大气的购物商城网站模板
- Zend Studio配置:使用PHP 7进行开发
- 远程服务器网刻系统,PXE网克工具免费的全自动PXE网刻工具
- Java TreeMap
- 计算机显卡(GPU)基础介绍
- Spring-IoC概念
- xxxx is not translated in zh-rCN, zh-rTW
- php handle 用用法,PHP_关于php fread()使用技巧,说明 string fread ( int handle, int le - phpStudy...