1919 **/
2020public abstract class BaseDialog {
2121
22-
2322 public Context context ;
2423 Dialog dialog ;
2524
@@ -29,7 +28,7 @@ public BaseDialog(Context context) {
2928
3029 Config config =config ();
3130
32- dialog .setCancelable (true );
31+ dialog .setCancelable (config . isCanCancelable () );
3332 dialog .getWindow ().setBackgroundDrawableResource (android .R .color .transparent );
3433 if (!config .isHasBgShadow ()) {
3534 dialog .getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_DIM_BEHIND );
@@ -54,6 +53,33 @@ public BaseDialog(Context context) {
5453
5554 }
5655
56+ public void setHeight (int height ){
57+ DisplayMetrics outMetrics = new DisplayMetrics ();
58+ ((Activity )context ).getWindowManager ().getDefaultDisplay ().getMetrics (outMetrics );
59+ int widthPixels = outMetrics .widthPixels ;
60+ int heightPixels = outMetrics .heightPixels ;
61+
62+ WindowManager .LayoutParams p = dialog .getWindow ().getAttributes ();
63+ p .gravity = Gravity .TOP ;
64+ p .height = height ;
65+ p .width = widthPixels ;
66+ dialog .getWindow ().setAttributes (p );
67+ }
68+
69+
70+ public void setHeightX (int split ){
71+ DisplayMetrics outMetrics = new DisplayMetrics ();
72+ ((Activity )context ).getWindowManager ().getDefaultDisplay ().getMetrics (outMetrics );
73+ int widthPixels = outMetrics .widthPixels ;
74+ int heightPixels = outMetrics .heightPixels ;
75+
76+ WindowManager .LayoutParams p = dialog .getWindow ().getAttributes ();
77+ p .gravity = Gravity .TOP ;
78+ p .height = heightPixels /split ;
79+ p .width = widthPixels ;
80+ dialog .getWindow ().setAttributes (p );
81+ }
82+
5783
5884 public abstract int getContentView ();
5985
@@ -77,8 +103,9 @@ protected <T extends View> T find(int viewId) {
77103
78104
79105 public class Config {
80- boolean hasBgShadow ;
81- int gravity ;
106+ private boolean hasBgShadow ;
107+ private int gravity ;
108+ private boolean canCancelable ;
82109
83110 public boolean isHasBgShadow () {
84111 return hasBgShadow ;
@@ -95,6 +122,14 @@ public int getGravity() {
95122 public void setGravity (int gravity ) {
96123 this .gravity = gravity ;
97124 }
125+
126+ public boolean isCanCancelable () {
127+ return canCancelable ;
128+ }
129+
130+ public void setCanCancelable (boolean canCancelable ) {
131+ this .canCancelable = canCancelable ;
132+ }
98133 }
99134
100135}
0 commit comments