ProgressBar实现进度条及ProgressDialog实现对话框进度条
2015-06-12 11:06
357 查看
//xxx程序猿
package com.example.jindu;
import android.support.v7.app.ActionBarActivity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity implements OnClickListener{
private ProgressBar pb;
private Button bt_add;
private Button bt_reduce;
private Button bt_reset;
private Button bt_dh;
private TextView textview;
private ProgressDialog proDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//启用窗口特征。启用带进度和不带进度进度条
requestWindowFeature(Window.FEATURE_PROGRESS);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
//显示两种进度条
setProgressBarVisibility(true);
setProgressBarIndeterminateVisibility(true);
//最大刻度常量是10000,现在所占是600/10000
setProgress(600);
init();
}
private void init() {
// TODO Auto-generated method stub
pb=(ProgressBar)findViewById(R.id.PB);
bt_add=(Button)findViewById(R.id.bt_add);
bt_add.setOnClickListener(this);
bt_reduce=(Button)findViewById(R.id.bt_reduce);
bt_reduce.setOnClickListener(this);
bt_reset=(Button)findViewById(R.id.bt_chong);
bt_reset.setOnClickListener(this);
bt_dh=(Button) findViewById(R.id.bt_duihuakuan);
bt_dh.setOnClickListener(this);
textview=(TextView) findViewById(R.id.TV);
//获得第一刻度
int first=pb.getProgress();
//获得第二刻度
int second=pb.getSecondaryProgress();
//获得最大刻度
int max=pb.getMax();
textview.setText("第一进度条进度百分百:"+(int)((first/(float)max)*100)+"%"+"第二进度条进度百分百:"+(int)((second/(float)max)*100)+"%");
}
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
switch(view.getId())
{
case R.id.bt_add:
{
//增加刻度
pb.incrementProgressBy(10);
pb.incrementSecondaryProgressBy(10);
break;
}
case R.id.bt_reduce:
{
//减少刻度
pb.incrementProgressBy(-10);
pb.incrementSecondaryProgressBy(-10);
break;
}
case R.id.bt_chong:
{
//重置刻度
pb.setProgress(30);
pb.setSecondaryProgress(60);
break;
}
case R.id.bt_duihuakuan:
{
//创建ProgressDialog对象
proDialog=new ProgressDialog(this);
//设置显示风格,横向进度条
proDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//设置标题
proDialog.setTitle("xxx程序猿");
//设置对话框耳朵文字信息
proDialog.setMessage("欢迎来到xxx程序猿课堂");
//设置图标
proDialog.setIcon(R.drawable.ic_launcher);
//设置最大进度
proDialog.setMax(100);
//设置初始化已经增长到的进度
proDialog.incrementProgressBy(50);
//进度条明确显示进度
proDialog.setIndeterminate(false);
//在ProgressDialog设置一个按钮
proDialog.setButton("确定" ,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "谢谢大家的支持", 0).show();
}
});
//设置退出对话框
proDialog.setCancelable(true);
//最后显示proDialog
proDialog.show();
}
break;
}
textview.setText("第一进度条进度百分百:"+(int)((pb.getProgress()/(float)pb.getMax())*100)+"%"+"第二进度条进度百分百:"+(int)((pb.getSecondaryProgress()/(float)pb.getMax())*100)+"%");
}
}
package com.example.jindu;
import android.support.v7.app.ActionBarActivity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity implements OnClickListener{
private ProgressBar pb;
private Button bt_add;
private Button bt_reduce;
private Button bt_reset;
private Button bt_dh;
private TextView textview;
private ProgressDialog proDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//启用窗口特征。启用带进度和不带进度进度条
requestWindowFeature(Window.FEATURE_PROGRESS);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
//显示两种进度条
setProgressBarVisibility(true);
setProgressBarIndeterminateVisibility(true);
//最大刻度常量是10000,现在所占是600/10000
setProgress(600);
init();
}
private void init() {
// TODO Auto-generated method stub
pb=(ProgressBar)findViewById(R.id.PB);
bt_add=(Button)findViewById(R.id.bt_add);
bt_add.setOnClickListener(this);
bt_reduce=(Button)findViewById(R.id.bt_reduce);
bt_reduce.setOnClickListener(this);
bt_reset=(Button)findViewById(R.id.bt_chong);
bt_reset.setOnClickListener(this);
bt_dh=(Button) findViewById(R.id.bt_duihuakuan);
bt_dh.setOnClickListener(this);
textview=(TextView) findViewById(R.id.TV);
//获得第一刻度
int first=pb.getProgress();
//获得第二刻度
int second=pb.getSecondaryProgress();
//获得最大刻度
int max=pb.getMax();
textview.setText("第一进度条进度百分百:"+(int)((first/(float)max)*100)+"%"+"第二进度条进度百分百:"+(int)((second/(float)max)*100)+"%");
}
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
switch(view.getId())
{
case R.id.bt_add:
{
//增加刻度
pb.incrementProgressBy(10);
pb.incrementSecondaryProgressBy(10);
break;
}
case R.id.bt_reduce:
{
//减少刻度
pb.incrementProgressBy(-10);
pb.incrementSecondaryProgressBy(-10);
break;
}
case R.id.bt_chong:
{
//重置刻度
pb.setProgress(30);
pb.setSecondaryProgress(60);
break;
}
case R.id.bt_duihuakuan:
{
//创建ProgressDialog对象
proDialog=new ProgressDialog(this);
//设置显示风格,横向进度条
proDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//设置标题
proDialog.setTitle("xxx程序猿");
//设置对话框耳朵文字信息
proDialog.setMessage("欢迎来到xxx程序猿课堂");
//设置图标
proDialog.setIcon(R.drawable.ic_launcher);
//设置最大进度
proDialog.setMax(100);
//设置初始化已经增长到的进度
proDialog.incrementProgressBy(50);
//进度条明确显示进度
proDialog.setIndeterminate(false);
//在ProgressDialog设置一个按钮
proDialog.setButton("确定" ,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "谢谢大家的支持", 0).show();
}
});
//设置退出对话框
proDialog.setCancelable(true);
//最后显示proDialog
proDialog.show();
}
break;
}
textview.setText("第一进度条进度百分百:"+(int)((pb.getProgress()/(float)pb.getMax())*100)+"%"+"第二进度条进度百分百:"+(int)((pb.getSecondaryProgress()/(float)pb.getMax())*100)+"%");
}
}
相关文章推荐
- Android 环境配置
- Fiddler有时抓不到请求可能的原因及解决方法
- LeetCodeOJ_198_House Robber_e
- 【ActionScript】ActionScript3.0对舞台组件的增删改查
- 在Unity3D里使用DLL
- 操作系统概念学习笔记 10 CPU调度
- 移动互联网领域的技术有哪些:
- iOS不规则按钮实现
- RequireJS学习笔记
- 数据结构存储的顺序和链式对比
- Java环境配置
- 十大推送方式整理
- c语言实现BMP图像转换为灰度图
- 程序员跳槽的10个建议
- SAT数学考题知识范围增量分析
- POJ-1006 Biorhythms (中国剩余定理)
- 瀑布流demo(完美注释)
- GenericServlet为什么有两个init方法
- Android初学习 - 以代码方式(非XML)创建一个布局
- 自定义倒计时TextView控件