Skip to content

Commit

Permalink
add some custom dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
leguang committed Dec 7, 2017
1 parent 2efb446 commit f697333
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -179,6 +179,7 @@ public void onClick(View view) {
}
})
.setDimAmount(0.3f)
.setMargin(30)
.show();
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");//显示。
Expand Down Expand Up @@ -181,10 +181,7 @@ public void onClick(View view) {
}
})
.setDimAmount(0.3F)
.setHeight(-2)
.setWidth(-2)
.setMargin(30)
.setGravity(Gravity.BOTTOM)
.show(getSupportFragmentManager());
break;

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/confirm_layout.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="40dp"
android:background="@drawable/white_round_corner_bg"
android:gravity="center_horizontal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class BaseDialog extends AppCompatDialog {
private int margin;//左右边距
private int width = -1;//宽度
private int height = -2;//高度
private float dimAmount = 0.5f;//灰度深浅
private float dimAmount = 0.5F;//灰度深浅
private int gravity;//是否底部显示
@StyleRes
private int animStyle;
Expand Down Expand Up @@ -103,9 +103,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public int getLayoutId() {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setCancelable(false);
setWidth(-2);
setHeight(-2);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f697333

Please sign in to comment.