zoukankan      html  css  js  c++  java
  • Android——————课外拓展ProgressBar & ProgressDialog

    1.有些时候我们可能需要加载一些东西 下载东西 需要看到加载东西 下载东西界面 

    2.首先 点击  进入 PorgressDialog使用界面 

    3.

     4.当点击progressBar练习:弹出:

     5.当点击progressDialog练习: 弹出:

    JAVA:

    package com.example.myapplication;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.app.Dialog;
    import android.app.ProgressDialog;
    import android.content.DialogInterface;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Toast;
    
    public class proActivity extends AppCompatActivity {
         private Button pro1,pro2;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_pro);
            pro1=findViewById(R.id.pro1);
            pro2=findViewById(R.id.pro2);
            pro1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ProgressDialog progressDialog=new ProgressDialog(proActivity.this);
                    progressDialog.setTitle("登陆中~~~");
                    progressDialog.setMessage("正在登陆");
                    progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "取消登陆", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            Toast.makeText(proActivity.this,"取消登陆",Toast.LENGTH_SHORT).show();
                        }
                    });
                    progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialogInterface) {
                            Toast.makeText(proActivity.this,"加载完成",Toast.LENGTH_SHORT).show();
                        }
                    });
                    progressDialog.show();
                }
            });
            pro2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ProgressDialog progressDialog=new ProgressDialog(proActivity.this);
                    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                    progressDialog.setTitle("提示");
                    progressDialog.setMessage("正在下载...");
                    progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "继续下载", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
    
                        }
                    });
                    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "取消下载", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
    
                        }
                    });
                    progressDialog.show();
                }
            });
        }
    }
    

      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:padding="15dp"
        android:orientation="vertical"
        >
        <Button
            android:layout_marginTop="200dp"
            android:id="@+id/pro1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="progressBar练习"
            android:textAllCaps="false"
            />
    
        <Button
            android:layout_marginTop="200dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="progressDialog练习"
            android:textAllCaps="false"
            android:id="@+id/pro2"/>
    
    </LinearLayout>
    

      

  • 相关阅读:
    Java 中的打印流
    Java 转换流的简单理解
    Java IO流之缓冲流(深入浅出学习)
    Java 中与IO流有关的集合(Properties集合)
    Java IO字符流
    Objective-C 中如何测量代码的效率
    android studio 转为eclipse快捷键后还存在的问题汇总
    Mac 下安装运行Rocket.chat
    Android属性动画完全解析(下),Interpolator和ViewPropertyAnimator的用法
    Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
  • 原文地址:https://www.cnblogs.com/skyfail/p/13939408.html
Copyright © 2011-2022 走看看