分类: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. STS 控制台 中文乱码(maven 中文乱码)

    用uriEncoding标签设置中文字符集就行了 <plugin> <groupId>org.apache.tomcat.maven</groupId> <a ...

  2. STS 自动生成 getter 和 setter

    1.Source --  Generate Getters and Setters

  3. jQuery实现页面关键词高亮

    示例代码,关键位置做了注释,请查看代码: <html> <head> <title>jQuery实现页面关键词高亮</title> <style ...

  4. systemctl的常用命令

    #systemctl #systemctl --all #systemctl list-units --type=sokect #systemctl list-units --type=service ...

  5. sqlserver 创建对某个存储过程执行情况的跟踪

    有时候需要抓取执行存储过程时某个参数的值,有时候程序调用存储过程执行后结果不太对,不确定是程序的问题还是存储过程的问题,需要单独执行存储过程看结果 即可用下面的方法 --=============== ...

  6. 〖Linux〗以后台方式启动/结束指定程序/命令(不受 exit 或点击窗口关闭按钮等终端退出操作的影响)

    #!/bin/bash - #=============================================================================== # # F ...

  7. JUC-闭锁:CountDownLatch

    CountDownLatch::闭锁,在完成某些运算是,只有其他所有线程的运算全部完成,当前运算才继续执行. 实例化:参数:设置一个计数器的值. final CountDownLatch latch ...

  8. topas解析(AIX)

    topas解析   topas 的显示信息和解析 (1) topas monitor for host:localhost  topas监控的主机名称localhost tue Aug 14 14:1 ...

  9. iOS利用SDWebImage实现缓存的计算与清理

    概述 可以仅仅清理图片缓存, 也可以清理所有的缓存文件(包括图片.视频.音频等). 详细 代码下载:http://www.demodashi.com/demo/10717.html 一般我们项目中的缓 ...

  10. Dell笔记本Ubuntu无线网卡驱动安装

    [日期:2010-06-09]   经过长时间学习Ubuntu无线网卡,,你可能会遇到Ubuntu无线网卡问题,,这里将介绍Ubuntu无线网卡问题的解决方法整了一晚上,终于在我的dell 1440上 ...