compile 'com.bigkoo:svprogresshud:1.0.6'
public class MainActivity extends Activity {
private SVProgressHUD mSVProgressHUD;
int progress = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSVProgressHUD = new SVProgressHUD(this);
mSVProgressHUD.setOnDismissListener(new OnDismissListener(){
@Override
public void onDismiss(SVProgressHUD hud) {
// todo something, like: finish current activity
Toast.makeText(getApplicationContext(),"dismiss",Toast.LENGTH_SHORT).show();
}
});
}
public void show(View view){
mSVProgressHUD.show();
}
public void showWithMaskType(View view){
mSVProgressHUD.showWithMaskType(SVProgressHUD.SVProgressHUDMaskType.None);
// mSVProgressHUD.showWithMaskType(SVProgressHUD.SVProgressHUDMaskType.Black);
// mSVProgressHUD.showWithMaskType(SVProgressHUD.SVProgressHUDMaskType.BlackCancel);
// mSVProgressHUD.showWithMaskType(SVProgressHUD.SVProgressHUDMaskType.Clear);
// mSVProgressHUD.showWithMaskType(SVProgressHUD.SVProgressHUDMaskType.ClearCancel);
// mSVProgressHUD.showWithMaskType(SVProgressHUD.SVProgressHUDMaskType.Gradient);
// mSVProgressHUD.showWithMaskType(SVProgressHUD.SVProgressHUDMaskType.GradientCancel);
}
public void showWithStatus(View view){
mSVProgressHUD.showWithStatus("加载中...");
}
public void showInfoWithStatus(View view){
mSVProgressHUD.showInfoWithStatus("这是提示", SVProgressHUD.SVProgressHUDMaskType.None);
}
public void showSuccessWithStatus(View view){
mSVProgressHUD.showSuccessWithStatus("恭喜,提交成功!");
}
public void showErrorWithStatus(View view){
mSVProgressHUD.showErrorWithStatus("不约,叔叔我们不约~", SVProgressHUD.SVProgressHUDMaskType.GradientCancel);
}
private Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
progress = progress + 5;
if (mSVProgressHUD.getProgressBar().getMax() != mSVProgressHUD.getProgressBar().getProgress()) {
mSVProgressHUD.getProgressBar().setProgress(progress);
mSVProgressHUD.setText("进度 "+progress+"%");
mHandler.sendEmptyMessageDelayed(0,500);
}
else{
mSVProgressHUD.dismiss();
}
}
};
public void showWithProgress(View view){
progress = 0;
mSVProgressHUD.getProgressBar().setProgress(progress);//先重设了进度再显示,避免下次再show会先显示上一次的进度位置所以要先将进度归0
mSVProgressHUD.showWithProgress("进度 " + progress + "%", SVProgressHUD.SVProgressHUDMaskType.Black);
mHandler.sendEmptyMessageDelayed(0,500);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
{
if(mSVProgressHUD.isShowing()){
mSVProgressHUD.dismiss();
mHandler.removeCallbacksAndMessages(null);
return false;
}
}
return super.onKeyDown(keyCode, event);
}
}
一些警告框,提示框等
最新推荐文章于 2019-09-09 01:40:06 发布