自定义dialog

 1 public class RemindPhotoDialog extends Dialog {
 2 
 3     private final String TAG = "RemindPhotoDialog";
 4     private static int default_width = 280; //默认宽
 5     private static int default_height = 440;//默认高度
 6     private View upload;
 7     private View exit;
 8     public static boolean ifDeletedAvatar;
 9 
10 
11 
12     public RemindPhotoDialog(Context context, int layout, int theme) {
13         this(context, layout, default_width, default_height, theme);
14     }
15 
16     public RemindPhotoDialog(Context context, int layout, int width, int height, int theme) {
17         super(context, theme);
18         setContentView(layout);
19         Window window = getWindow();
20         WindowManager.LayoutParams params = window.getAttributes();
21         float density = getDensity(context);
22 //        params.width = (int) (width * density);
23         params.width = DeviceUtils.getScreenWidth() - PixelUtils.getPxByDp(32 * 2);
24 //        params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
25         params.height = LinearLayout.LayoutParams.WRAP_CONTENT;
26 //        params.width = Config.width;//- 35 * density
27 //        params.height = (int) (Config.height - 100 * density);//125
28         params.gravity = Gravity.CENTER;
29         window.setAttributes(params);
30         window.setWindowAnimations(R.style.reportDialogWindowAnim);
31 
32         initView();
33         setListener();
34     }
35 
36 
37     private void initView() {
38         upload = findViewById(R.id.layout_ok);
39         exit = findViewById(R.id.iv_exit);
40 
41         exit.setOnClickListener(new View.OnClickListener() {
42             @Override
43             public void onClick(View v) {
44                 dismiss();
45             }
46         });
47         upload.setOnClickListener(new View.OnClickListener() {
48             @Override
49             public void onClick(View v) {
50                 getContext().startActivity(new Intent(getContext(),MyProfileActivity.class));
51                 ifDeletedAvatar = true;
52                 dismiss();
53             }
54         });
55     }
56 
57     private void setListener() {
58     }
59 
60     private float getDensity(Context context) {
61         Resources resources = context.getResources();
62         DisplayMetrics dm = resources.getDisplayMetrics();
63         return dm.density;
64     }
65 
66     @Override
67     public void show() {
68         super.show();
69     }
70 
71 
72 }

 2、资源文件

1  

in

 1 
 2  3     android:duration="200"
 4     android:interpolator="@android:anim/linear_interpolator" >
 5     <translate
 6         android:fromYDelta="100%p"
 7         android:toYDelta="0" />
 8     <alpha
 9         android:fromAlpha="0.0"
10         android:toAlpha="1.0" />
11 
12 

out

 1 
 2  3     android:duration="200"
 4     android:interpolator="@android:anim/linear_interpolator">
 5     <translate
 6         android:fromYDelta="0"
 7         android:toYDelta="100%p" />
 8     <alpha
 9         android:fromAlpha="1.0"
10         android:toAlpha="0" />
11 

 style

 1 

 

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