分类:C#、Android、VS2015;

创建日期:2016-02-08

一、简介

进度条对话框(ProgressDialog)常用于不能在短时间内快速完成的操作,显示进度条的目的是为了让用户明白程序正在处理的进度,避免用户感觉莫名其妙。

本示例演示了两种进度条的基本用法:条形进度条和圆形进度条。

二、示例==Demo03ProgressDialog

1、运行截图

 

2、添加Demo03_ProgressDialog.axml文件

在layout文件夹下添加该文件。

<?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">
<Button
android:id="@+id/btnPprogress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="条形进度条" />
<Button
android:id="@+id/btnCircle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="圆形进度条" />
</LinearLayout>

3、添加Demo03ProgressDialog.cs文件

在SrcActivity文件夹下添加该文件。

using System;
using Android.App;
using Android.OS;
using Android.Widget; namespace ch06demos.SrcActivity
{
[Activity(Label = "Demo03ProgressDialog")]
public class Demo03ProgressDialog : Activity
{
private int progress;
private ProgressDialog dialog; protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Demo03_ProgressDialog);
var btnProgress = FindViewById<Button>(Resource.Id.btnPprogress);
btnProgress.Click += BtnProgress_Click;
var btnCircle = FindViewById<Button>(Resource.Id.btnCircle);
btnCircle.Click += BtnCircle_Click;
} private void BtnProgress_Click(object sender, EventArgs e)
{
progress = ;
dialog = new ProgressDialog(this)
{
Progress = progress,
Indeterminate = false,
};
dialog.SetProgressStyle(ProgressDialogStyle.Horizontal);
dialog.SetTitle("条形进度条示例");
dialog.SetMessage("正在下载……");
dialog.SetIcon(Resource.Drawable.Icon);
dialog.SetCancelable(true);
dialog.SetButton("取消", delegate
{
Toast.MakeText(this, "已取消下载!", ToastLength.Long).Show();
});
dialog.Show();
RunTask(showProgress: false);
} private void BtnCircle_Click(object sender, EventArgs e)
{
progress = ;
dialog = new ProgressDialog(this)
{
Progress = progress,
Indeterminate = false
};
dialog.SetProgressStyle(ProgressDialogStyle.Spinner);
dialog.SetTitle("环转圆形进度条示例");
dialog.SetMessage("正在下载……");
dialog.SetIcon(Resource.Drawable.Icon);
dialog.SetCancelable(true);
dialog.SetButton("取消", delegate
{
Toast.MakeText(this, "已取消下载!", ToastLength.Long).Show();
});
dialog.Show();
RunTask(showProgress: true);
} //模拟长时间执行的任务
private void RunTask(bool showProgress)
{
System.Threading.Tasks.Task.Run(() =>
{
while (progress < )
{
dialog.Progress = progress++;
if (showProgress)
{
RunOnUiThread(() =>
{
dialog.SetMessage("正在下载……" + progress + "%");
});
}
System.Threading.Thread.Sleep();
}
dialog.Cancel();
});
}
}
}

运行。

【Android】6.3 ProgressDialog的更多相关文章

  1. 【Android】一种提高Android应用进程存活率新方法

    [Android]一种提高Android应用进程存活率新方法 SkySeraph Jun. 19st 2016 Email:skyseraph00@163.com 更多精彩请直接访问SkySeraph ...

  2. 【Android】Eclipse自动编译NDK/JNI的三种方法

    [Android]Eclipse自动编译NDK/JNI的三种方法 SkySeraph Sep. 18th  2014 Email:skyseraph00@163.com 更多精彩请直接访问SkySer ...

  3. 【Android】不依赖焦点和选中的TextView跑马灯

    前言 继承TextView,并仿照源码修改而来,主要是取消了焦点和选中了判断,也不依赖文本的宽度. 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民 ...

  4. 【Android】Android 移动应用数据到SD

    [Android]Android 移动应用数据到SD 在应用的menifest文件中指定就可以了,在 <manifest> 元素中包含android:installLocation 属性, ...

  5. 【Android】如何快速构建Android Demo

    [Android]如何快速构建Android Demo 简介 在 Android 学习的过程中,经常需要针对某些项目来写一些测试的例子,或者在做一些 demo 的时候,都需要先写 Activity 然 ...

  6. 【Android】IntentService & HandlerThread源码解析

    一.前言 在学习Service的时候,我们一定会知道IntentService:官方文档不止一次强调,Service本身是运行在主线程中的(详见:[Android]Service),而主线程中是不适合 ...

  7. 【转】(转)【Android】Paint的效果研究

    转自:http://wpf814533631.iteye.com/blog/1847661 (转)[Android]Paint的效果研究 博客分类: android   在Paint中有很多的属性可以 ...

  8. 【Android】首次进入应用时加载引导界面

    参考文章: [1]http://blog.csdn.net/wsscy2004/article/details/7611529 [2]http://www.androidlearner.net/and ...

  9. 【Android】【录音】Android录音--AudioRecord、MediaRecorder

    [Android][录音]Android录音--AudioRecord.MediaRecorder Android提供了两个API用于实现录音功能:android.media.AudioRecord. ...

随机推荐

  1. 为什么学习Python及Python环境安装

    大部分人在工作中可能是以c/c++.java之类的语言为主.这也可能是我们接触的第一个开发语言,这类语言一般有丰富地类库.高效地运行速率.灵活地组合控制,须要经过编译在运行.适用于大型的项目proje ...

  2. 解决 jersey 单jar包 IME media type text/plain was not found.

    1.maven-assembly-plugin  换成 --> maven-shade-plugin <plugins> <!-- shade插件打包成jar包 --> ...

  3. java String字符串

      五.java数据类型之String(字符串) CreateTime--2017年7月21日16:17:45 Author:Marydon (一)数据格式 (二)初始化 // 方式一 String ...

  4. Codeforces554C:Kyoya and Colored Balls(组合数学+费马小定理)

    Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...

  5. win10下Visual Studio 2015,C++ x64编译zlib

    前提安装了visual studio 2015      PS.几乎所有方式,x64的编译都会有点坑,鉴于网上的x86编译方式非常的多,所以不再累赘x86的编译方式 zlib下载源: 官网:http: ...

  6. 微信小程序:input输入框和form表单几种传值和取值方式

    1.传值:index下标传值.页面navigator传值 1.index下标 实现方式是:data-index="{{index}}"挖坑及e.currentTarget.data ...

  7. JavaScript-jQuery插件开发全解析

    摘自:http://www.iteye.com/topic/545971 jQuery插件的开发包括两种: 一种是类级别的插件开发,即给jQuery添加新的全局函数,相当于给jQuery类本身添加方法 ...

  8. nyoj------------找球号(一)

    找球号(一) 时间限制:3000 ms  |           内存限制:65535 KB 难度:3   描述 在某一国度里流行着一种游戏.游戏规则为:在一堆球中,每个球上都有一个整数编号i(0&l ...

  9. js中的let和var

    在ES6中,应该尽量使用const和let来声明变量,而尽量避免使用var. var的缺点是它的作用域比较混乱,使用let能够保证清晰的作用域. 下面看一个小例子. var x = 3; if(x== ...

  10. firefox 前端开发插件

    http://blog.csdn.net/xjinza/article/details/6856249