From f697333c426370fa5e4de439ff92a6ad5f25aa95 Mon Sep 17 00:00:00 2001 From: langmanleguang Date: Thu, 7 Dec 2017 11:26:04 +0800 Subject: [PATCH] add some custom dialog. --- .../java/cn/itsite/adialog/demo/demo/DialogActivity.java | 7 ++++--- .../itsite/adialog/demo/demo/DialogFragmentActivity.java | 5 +---- app/src/main/res/layout/confirm_layout.xml | 4 ++-- .../main/java/cn/itsite/adialog/dialog/BaseDialog.java | 6 ++---- .../main/java/cn/itsite/adialog/dialog/LoadingDialog.java | 2 ++ .../itsite/adialog/dialogfragment/BaseDialogFragment.java | 8 +++----- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/cn/itsite/adialog/demo/demo/DialogActivity.java b/app/src/main/java/cn/itsite/adialog/demo/demo/DialogActivity.java index 25ae759..3967fde 100644 --- a/app/src/main/java/cn/itsite/adialog/demo/demo/DialogActivity.java +++ b/app/src/main/java/cn/itsite/adialog/demo/demo/DialogActivity.java @@ -151,9 +151,9 @@ public void onClick(View view) { .show(); break; case R.id.loading: - - new LoadingDialog(this).setDimAmount(0).show(); - + BaseDialog loading = new LoadingDialog(this).setDimAmount(0); + loading.show(); + loading.setCancelable(true); break; case R.id.tips: new BaseDialog(this) @@ -179,6 +179,7 @@ public void onClick(View view) { } }) .setDimAmount(0.3f) + .setMargin(30) .show(); break; diff --git a/app/src/main/java/cn/itsite/adialog/demo/demo/DialogFragmentActivity.java b/app/src/main/java/cn/itsite/adialog/demo/demo/DialogFragmentActivity.java index 13565dc..4e92eac 100644 --- a/app/src/main/java/cn/itsite/adialog/demo/demo/DialogFragmentActivity.java +++ b/app/src/main/java/cn/itsite/adialog/demo/demo/DialogFragmentActivity.java @@ -72,7 +72,7 @@ public void onClick(View view) { }); } }) - .setDimAmount(0.3f)//设置window的暗度。 + .setDimAmount(0.3F)//设置window的暗度。 .setGravity(Gravity.TOP)//位置有多种选择。 .setAnimStyle(R.style.SlideAnimation)//进入和退出动画。 .show(getSupportFragmentManager(), "MyBaseDialogFragment");//显示。 @@ -181,10 +181,7 @@ public void onClick(View view) { } }) .setDimAmount(0.3F) - .setHeight(-2) - .setWidth(-2) .setMargin(30) - .setGravity(Gravity.BOTTOM) .show(getSupportFragmentManager()); break; diff --git a/app/src/main/res/layout/confirm_layout.xml b/app/src/main/res/layout/confirm_layout.xml index 47dd769..07c19da 100644 --- a/app/src/main/res/layout/confirm_layout.xml +++ b/app/src/main/res/layout/confirm_layout.xml @@ -1,7 +1,7 @@ 0) { - lp.height = Utils.getScreenHeight(getContext()) - 2 * Utils.dp2px(getContext(), margin); - } else if (width > 0) { + if (height > 0) { lp.height = Utils.dp2px(getContext(), height); } else { lp.height = height; diff --git a/library/src/main/java/cn/itsite/adialog/dialog/LoadingDialog.java b/library/src/main/java/cn/itsite/adialog/dialog/LoadingDialog.java index 9489a46..e2c8985 100644 --- a/library/src/main/java/cn/itsite/adialog/dialog/LoadingDialog.java +++ b/library/src/main/java/cn/itsite/adialog/dialog/LoadingDialog.java @@ -41,6 +41,8 @@ public int getLayoutId() { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setCancelable(false); + setWidth(-2); + setHeight(-2); } @Override diff --git a/library/src/main/java/cn/itsite/adialog/dialogfragment/BaseDialogFragment.java b/library/src/main/java/cn/itsite/adialog/dialogfragment/BaseDialogFragment.java index 2ca84b0..1e78ca3 100644 --- a/library/src/main/java/cn/itsite/adialog/dialogfragment/BaseDialogFragment.java +++ b/library/src/main/java/cn/itsite/adialog/dialogfragment/BaseDialogFragment.java @@ -29,8 +29,8 @@ public class BaseDialogFragment extends AppCompatDialogFragment { private static final String ANIM = "anim_style"; private static final String LAYOUT = "layout_id"; private int margin;//左右边距 - private int width = -1;//宽度 - private int height = -2;//高度 + private int width = -1;//宽度,-2代表包裹内容 + private int height = -2;//高度,-2代表包裹内容 private float dimAmount = 0.5F;//灰度深浅 private int gravity;//是否底部显示 @StyleRes @@ -124,9 +124,7 @@ private void initWindow() { lp.width = width; } //设置dialog高度 - if (margin > 0) { - lp.height = Utils.getScreenHeight(getContext()) - 2 * Utils.dp2px(getContext(), margin); - } else if (width > 0) { + if (height > 0) { lp.height = Utils.dp2px(getContext(), height); } else { lp.height = height;