android进度条对话框
程序员文章站
2022-05-16 20:57:53
...
package cn.edu.xynu.computer.myapplication;
import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
Button btnone;
Button btntwo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnone = findViewById(R.id.btnOne);
btntwo = findViewById(R.id.btnTwo);
btnone.setOnClickListener(this);
btntwo.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.btnOne:
ProgressDialog pd1 = new ProgressDialog(this);
pd1.setTitle("HORIZONTAL PROGRESS DIAGLOG");
pd1.setIcon(R.mipmap.ic_launcher);
pd1.setMessage("software is updating, please wait...");
pd1.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd1.setCancelable(true);
pd1.setIndeterminate(true);
pd1.show();
break;
case R.id.btnTwo:
ProgressDialog pd2 = new ProgressDialog(this);
pd2.setTitle("software downloading");
pd2.setIcon(R.mipmap.ic_launcher_round);
pd2.setMessage("software is downloading...");
pd2.setCancelable(false);
pd2.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pd2.show();
break;
}
}
}
结果如下所示