ProgressDialog和AlertDialog类似,都可以在界面上弹出一个对话框,都能够屏蔽掉其他控件的交互能力。不同的是,ProgressDialog会在对话框中显示一个进度条,一般表示当前操作比较耗时,请用户耐心等待。
package com.example.textviewactivity;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private EditText editText;
private ImageView imageView;
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button=findViewById(R.id.button);
editText=findViewById(R.id.edit_text);
imageView=findViewById(R.id.image_view);
progressBar=findViewById(R.id.progress_bar);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button:
ProgressDialog progressDialog=new ProgressDialog(MainActivity.this);
progressDialog.setTitle("this is progressDialog");
progressDialog.setMessage("你好吗?");
progressDialog.setCancelable(true);
progressDialog.show();
default:
break;
}
}
}
执行结果