进度条ProgressBar及ProgressDialog的示例分析
这篇文章将为大家详细讲解有关进度条ProgressBar及ProgressDialog的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

成都创新互联自2013年起,是专业互联网技术服务公司,拥有项目成都网站制作、成都网站设计、外贸营销网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元文昌做网站,已为上家服务,为文昌各地企业和个人服务,联系电话:028-86922220
废话不多说,直接上代码
Main代码
package processdemo.example.administrator.processbardemo;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
/*ProgressBar
简介:ProgressBar是进度条组件,通常用于向用户展示某个耗时操作完成的进度,而不让用户感觉是程序失去了响应,从而更好地提升用户界面的友好性
课程目标:
1、制定ProgressBar显示风格(系统默认)
2、ProgressBar的分类
水平进度条,能精确显示,圆圈进度条,不精确显示
3、标题上ProgressBar的设置
4、ProgressBar的关键属性
5、ProgressBar的关键方法
6、ProgressDiglog的基础使用
7、自定义ProgressBar样式*/
private ProgressBar progressBar3;
private Button show;
private Button add;
private Button res;
private Button reset;
private TextView textView;
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 启用窗口特征,启用带进度的进度条和不带进度的进度条,
requestWindowFeature(Window.FEATURE_PROGRESS);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
setProgressBarVisibility(true);
setProgressBarIndeterminateVisibility(false);
// 最大值为Max=10000;
//setProgress(600);
init();
}
private void init() {
;
progressBar3= (ProgressBar) findViewById(R.id.progressBar3);
show= (Button) findViewById(R.id.show);
add= (Button) findViewById(R.id.add);
res= (Button) findViewById(R.id.res);
reset= (Button) findViewById(R.id.reset);
textView= (TextView) findViewById(R.id.textView);
int first=progressBar3.getProgress();/*获取第一进度*/
int second=progressBar3.getSecondaryProgress();/*获取第二进度*/
int max=progressBar3.getMax();/*获取最大进度*/
textView.setText("第一进度条百分比"+(int)((first/(float)max)*100)+"%"+"第二进度条百分比"+(int)(second/(float)max*100)+"%");
add.setOnClickListener(this);
res.setOnClickListener(this);
reset.setOnClickListener(this);
show.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.add:
progressBar3.incrementProgressBy(10);
progressBar3.incrementSecondaryProgressBy(10);
break;
case R.id.res:
progressBar3.incrementProgressBy(-10);
progressBar3.incrementSecondaryProgressBy(-10);
break;
case R.id.reset:
progressBar3.setProgress(50);
progressBar3.setSecondaryProgress(50);
break;
case R.id.show:
// 新建ProgressDialog对象
progressDialog=new ProgressDialog(MainActivity.this);
// 设置显示风格
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// 设置标题
progressDialog.setTitle("慕课网");
// 设置对话框的内容
progressDialog.setMessage("欢迎大家支持慕课网");
// 设置图标
progressDialog.setIcon(R.mipmap.ic_launcher);
/*设置关于进度条的一些属性*/
// 设置最大进度
progressDialog.setMax(100);
// 设置初始化已经增长的进度
progressDialog.incrementProgressBy(50);
// 设置进度条明确显示进度
progressDialog.setIndeterminate(false);
/* 设定一个确定按钮*/
progressDialog.setButton(DialogInterface.BUTTON_POSITIVE,"确定", new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"欢迎大家支持慕课网",Toast.LENGTH_SHORT).show();
}
});
// 是否可以通过返回按钮来取消对话框
progressDialog.setCancelable(true);
// 显示ProgressDialog
progressDialog.show();
}
textView.setText("第一进度条百分比"+(int)((progressBar3.getProgress()/(float)progressBar3.getMax())*100)+"%"+"第二进度条百分比"+(int)(progressBar3.getSecondaryProgress()/(float)progressBar3.getMax()*100)+"%");
}
}layout中activity_main.xml代码
layout中progress.xml
关于“进度条ProgressBar及ProgressDialog的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
分享名称:进度条ProgressBar及ProgressDialog的示例分析
网页网址:http://www.cqwzjz.cn/article/gjehcd.html


咨询
建站咨询
