自定义Dialog

仿IOS自定义的Dialog:


自定义Dialog_第1张图片
Screenshot_2016-01-15-14-45-08-024.png

1、Util帮助类创建dialog

public class DialogUtils {
    public static Dialog createLoadingDialog(Context context, String msg) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.layout_loading_dialog, null);
        // 得到加载view
        LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);
        // 加载布局
        TextView msgTV = (TextView) v.findViewById(R.id.tv_msg);
        msgTV.setText(msg);
        Dialog loadingDialog = new Dialog(context, R.style.loading_dialog);// 创建自定义样式dialog
        loadingDialog.setCancelable(false);// 不可以用"返回键"取消
        loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        return loadingDialog;
    }
}

2、布局文件 :loading_dialog.xml



    
    

style:progressbar_circle.xml


drawable:




3、在BaseActivity中进行show和dismiss操作。

···
private Dialog mWaitDlg;
private boolean mIsShowing;public void openWaitDialog() {
    if (mWaitDlg != null) return;
    mWaitDlg = DialogUtils.createLoadingDialog(this, "请稍候...");
    mWaitDlg.show();
}
public void openWaitDialog(String msg) {
    if (mWaitDlg != null) return;
    mWaitDlg = DialogUtils.createLoadingDialog(this, msg);
    mWaitDlg.show();
}
public void closeWaitDialog() {
    if (mWaitDlg == null) return;
    mWaitDlg.dismiss();
    mWaitDlg = null;
}
···

源码:点击前往github

你可能感兴趣的:(自定义Dialog)