LoadingUtils.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.topsoft.jianyu.util;
  2. import android.app.Dialog;
  3. import android.content.Context;
  4. import android.view.LayoutInflater;
  5. import android.view.View;
  6. import android.widget.LinearLayout;
  7. import android.widget.RelativeLayout;
  8. import android.widget.TextView;
  9. import com.topsoft.jianyu.R;
  10. /**
  11. * Created by wanghuidong on 2017/12/25.
  12. */
  13. public class LoadingUtils {
  14. public static Dialog createLoadingDialog(Context context, String msg) {
  15. LayoutInflater inflater = LayoutInflater.from(context);
  16. View v = inflater.inflate(R.layout.simple_loading_view, null);// 得到加载view
  17. RelativeLayout layout = (RelativeLayout) v
  18. .findViewById(R.id.dialog_loading_view);// 加载布局
  19. TextView tipTextView = (TextView) v.findViewById(R.id.simple_loading_view_text);// 提示文字
  20. tipTextView.setText(msg);// 设置加载信息
  21. Dialog loadingDialog = new Dialog(context, R.style.simple_progress_dialog_three_style);// 创建自定义样式dialog
  22. loadingDialog.setCancelable(true); // 是否可以按“返回键”消失
  23. loadingDialog.setCanceledOnTouchOutside(false); // 点击加载框以外的区域
  24. loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
  25. LinearLayout.LayoutParams.WRAP_CONTENT,
  26. LinearLayout.LayoutParams.WRAP_CONTENT));// 设置布局
  27. loadingDialog.show();
  28. return loadingDialog;
  29. }
  30. /**
  31. * 关闭dialog
  32. * <p>
  33. * http://blog.csdn.net/qq_21376985
  34. *
  35. * @param mDialogUtils
  36. */
  37. public static void closeDialog(Dialog mDialogUtils) {
  38. if (mDialogUtils != null && mDialogUtils.isShowing()) {
  39. mDialogUtils.dismiss();
  40. }
  41. }
  42. }