PhotoViewDialog.java
1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.hjx.parent.dialog;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.hjx.parent.databinding.DialogPhotoViewBinding;
public class PhotoViewDialog extends BaseDialog<DialogPhotoViewBinding> {
public PhotoViewDialog(Context context) {
super(context);
}
private String url;
@Override
public void initView() {
setupWindow();
setCancelable(true);
binding.btnClose.setOnClickListener(v -> dismiss());
}
private void setupWindow() {
// 在显示 Dialog 之前对窗口进行设置
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// 设置状态栏背景透明
getWindow().setStatusBarColor(Color.TRANSPARENT);
// 让内容延伸到状态栏区域,并保持状态栏和导航栏的显示
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
@Override
public void onDialogStart() {
super.onDialogStart();
Glide.with(getContext()).load(url).into(binding.photoView);
}
public void show(String url) {
this.url = url;
super.show();
}
@NonNull
@Override
public DialogPhotoViewBinding getBinding() {
return DialogPhotoViewBinding.inflate(getLayoutInflater());
}
}