android 组件 ProgressDialog实例

本例子通过点击一个按钮弹出一个进度对话框,并在5秒之后自动消失。

主要知识点:

// 实例化进度对话框

progressDialog = ProgressDialog.show(this, "系统提示", "正在加载,请稍后...");


布局文件:progress_dialog_layout.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <Button
        android:id="@+id/btn_show"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="show"
        android:text="弹出进度对话框" />


</LinearLayout>


AtyProgressDialog.java文件:


package com.fxj.composit;


import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;


import com.fxj.compractice.R;


public class AtyProgressDialog extends Activity {
private ProgressDialog progressDialog;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.progress_dialog_layout);


}


// 按钮监听事件
public void show(View view) {
// 实例化进度对话框
progressDialog = ProgressDialog.show(this, "系统提示", "正在加载,请稍后...");

// 开启新线程,在线程中5秒后 取消进度对话框。
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);// 线程睡眠5秒
progressDialog.dismiss();// 进度对话框消失
} catch (InterruptedException e) {
e.printStackTrace();
}


}
}).start();
}
}


运行效果:




结束。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

子林Android

感谢老板,老板大气!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值