zhangzengfei
2022-01-10 4496b59ab27d569df1da7ef634e02273b3a9618a
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
package com.basic.security.widget;
 
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
 
import com.basic.security.R;
 
public class MyToast {
    private final TextView textView;
    private Toast mToast;
    private boolean isShow = false;
 
    private MyToast(Context context, CharSequence text, int duration) {
        View v = LayoutInflater.from(context).inflate(R.layout.eplay_toast, null);
        textView = v.findViewById(R.id.textView1);
        textView.setText(text);
        mToast = new Toast(context);
        mToast.setDuration(duration);
        mToast.setView(v);
    }
 
    public static MyToast makeText(Context context, CharSequence text, int duration) {
        return new MyToast(context, text, duration);
    }
 
    public void setText(CharSequence text) {
        if (textView != null) {
            textView.setText(text);
        }
    }
 
    public void show() {
        if (mToast != null) {
            mToast.show();
        }
    }
 
    public void setGravity(int gravity, int xOffset, int yOffset) {
        if (mToast != null) {
            mToast.setGravity(gravity, xOffset, yOffset);
        }
    }
 
    public void setDuration(int duration) {
        if (mToast != null) {
            mToast.setDuration(duration);
        }
    }
 
}