21
public class NotRegisterDialog  {
22
    private Context context;
23
    private Dialog dialog;
24
    private Display display;
25
26
    private ImageView goIntent,neglect,close,logoDialog;
27
    private TextView content;
28
29
30
    public NotRegisterDialog(Context context) {
31
        this.context = context;
32
        WindowManager windowManager = (WindowManager) context
33
                .getSystemService(Context.WINDOW_SERVICE);
34
        display = windowManager.getDefaultDisplay();
35
    }
36
37
    public NotRegisterDialog builder() {
38
        // 获取Dialog布局
39
        View view = LayoutInflater.from(context).inflate(
40
                R.layout.dialog_not_login, null);
41
42
        // 获取自定义Dialog布局中的控件
43
        RelativeLayout  bgNotLogin = (RelativeLayout) view.findViewById(R.id.bgNotLogin);
44
        goIntent = view.findViewById(R.id.goIntent);
45
        neglect = view.findViewById(R.id.neglect);
46
        close   = view.findViewById(R.id.close);
47
        content = view.findViewById(R.id.content);
48
         logoDialog   = view.findViewById(R.id.logoDialog);
49
50
51
        // 定义Dialog布局和参数
52
        dialog = new Dialog(context, R.style.AlertDialogStyle);
53
        dialog.setContentView(view);
54
55
        // 调整dialog背景大小
56
        bgNotLogin.setLayoutParams(new FrameLayout.LayoutParams(
57
                DensityUtil.dip2px(context,  268),
58
                DensityUtil.dip2px(context, 296)
59
        ));
60
61
        return this;
62
    }
63
64
    public NotRegisterDialog setContent(String str){
65
        content.setText(str);
66
        return this;
67
    }
68
69
    public NotRegisterDialog setGoIntentImg(@DrawableRes int str){
70
        goIntent.setImageResource(str);
71
        return this;
72
    }
73
    public NotRegisterDialog setlogoDialogImg(@DrawableRes int str){
74
        logoDialog.setImageResource(str);
75
        return this;
76
    }
77
78
79
80
    public NotRegisterDialog setCancelable(boolean cancel) {
81
        dialog.setCancelable(cancel);
82
        dialog.setCanceledOnTouchOutside(cancel);
83
        return this;
84
    }
85
86
    public  NotRegisterDialog setGoRegister(View.OnClickListener listener){
87
        if (goIntent!=null){
88
            goIntent.setOnClickListener(view ->{
89
                listener.onClick(view);
90
                dialog.dismiss();
91
            });
92
        }
93
        return this;
94
    }
95
96
    public  NotRegisterDialog setCancle(View.OnClickListener listener){
97
        if (neglect!=null){
98
            neglect.setOnClickListener(view ->{
99
                listener.onClick(view);
100
                dialog.dismiss();
101
            });
102
        }
103
104
        return this;
105
    }
106
    public void show() {
107
        close.setOnClickListener(new View.OnClickListener() {
108
            @Override
109
            public void onClick(View view) {
110
                dialog.dismiss();
111
            }
112
        });
113
        dialog.show();
114
    }
115
116
}

BIN
app/src/main/res/drawable-xxhdpi/bg_not_login_dialog.png


BIN
app/src/main/res/drawable-xxhdpi/ic_black_bold.png


BIN
app/src/main/res/drawable-xxhdpi/ic_go_login.png


BIN
app/src/main/res/drawable-xxhdpi/ic_neglect.png


+ 5 - 0
app/src/main/res/drawable/bg_white_fillet30.xml

@ -0,0 +1,5 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3
    <solid android:color="@color/white"/>
4
    <corners android:radius="30dp"/>
5
</shape>

+ 72 - 0
app/src/main/res/layout/dialog_not_login.xml

@ -0,0 +1,72 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    xmlns:tools="http://schemas.android.com/tools"
5
    xmlns:app="http://schemas.android.com/apk/res-auto"
6
    tools:background="#f1f1"
7
    android:id="@+id/bgNotLogin"
8
    android:layout_height="match_parent">
9
10
    <androidx.constraintlayout.widget.ConstraintLayout
11
        android:layout_centerInParent="true"
12
        android:layout_width="268dp"
13
        android:background="@drawable/bg_white_fillet30"
14
        android:layout_height="296dp">
15
        <ImageView
16
            android:id="@+id/close"
17
            android:padding="5dp"
18
            android:src="@drawable/ic_black_bold"
19
            android:layout_marginTop="10dp"
20
            android:layout_marginEnd="20dp"
21
            app:layout_constraintEnd_toEndOf="parent"
22
            app:layout_constraintTop_toTopOf="parent"
23
            android:layout_width="wrap_content"
24
            android:layout_height="wrap_content"/>
25
        <ImageView
26
            android:id="@+id/logoDialog"
27
            android:layout_marginTop="15dp"
28
            app:layout_constraintTop_toTopOf="parent"
29
            app:layout_constraintEnd_toEndOf="parent"
30
            app:layout_constraintStart_toStartOf="parent"
31
            tools:src="@drawable/bg_not_login_dialog"
32
            android:layout_width="wrap_content"
33
            android:layout_height="wrap_content"/>
34
35
        <TextView
36
            android:lineSpacingMultiplier="1.2"
37
            android:layout_marginEnd="16dp"
38
            android:layout_marginStart="16dp"
39
            android:lineSpacingExtra="2dp"
40
            android:layout_marginTop="15dp"
41
            android:id="@+id/content"
42
            android:layout_width="match_parent"
43
            android:layout_height="wrap_content"
44
            tools:text="我知道你关注我很久了快来注册登录吧\n登录后可以在部分充电桩扫码充电认证车主还有充电优惠"
45
            android:textColor="#ff0e0e0e"
46
            android:textSize="14sp"
47
            app:layout_constraintEnd_toEndOf="parent"
48
            app:layout_constraintStart_toStartOf="parent"
49
            app:layout_constraintTop_toBottomOf="@id/logoDialog" />
50
51
        <ImageView
52
            app:layout_constraintBottom_toBottomOf="parent"
53
            android:id="@+id/neglect"
54
            app:layout_constraintStart_toStartOf="parent"
55
            app:layout_constraintTop_toBottomOf="@id/content"
56
            android:src="@drawable/ic_neglect"
57
            app:layout_constraintEnd_toStartOf="@id/goIntent"
58
            android:layout_width="wrap_content"
59
            android:layout_height="wrap_content"/>
60
61
        <ImageView
62
            app:layout_constraintBottom_toBottomOf="parent"
63
            app:layout_constraintEnd_toEndOf="parent"
64
            app:layout_constraintStart_toEndOf="@+id/neglect"
65
            android:id="@+id/goIntent"
66
            app:layout_constraintTop_toBottomOf="@id/content"
67
            tools:src="@drawable/ic_go_login"
68
            android:layout_width="wrap_content"
69
            android:layout_height="wrap_content"/>
70
    </androidx.constraintlayout.widget.ConstraintLayout>
71
72
</RelativeLayout>

Sign In - Gogs: Go Git Service

Sign In