CommToast.java
1.8 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
60
61
62
package com.chudiangameplay.android.tool;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.chudiangameplay.android.R;
/**
* Created by Administrator on 2016/8/21.
*/
public class CommToast {
public static CommToast mToast = null;
private static Toast toast = null;
private static Handler mhandler = new Handler();
private static Runnable r = new Runnable() {
public void run() {
toast.cancel();
toast = null;
}
;
};
public static void showToast(Context context, String tvString) {
// if(toast != null){
// Log.i("fulu","toast is not null!");
// return;
// }
// View layout = LayoutInflater.from(context.getApplicationContext()).inflate(R.layout.view_comm_toast,null);
// TextView text = (TextView) layout.findViewById(R.id.text);
// text.getBackground().setAlpha((int)(255*0.7));
// text.setText(tvString);
// mhandler.removeCallbacks(r);
// if(toast != null){
// toast.setText(tvString);
// }else{
// toast = new Toast(context.getApplicationContext());
// toast.setDuration(Toast.LENGTH_SHORT);
// toast.setView(layout);
// toast.show();
// }
// if (Looper.myLooper() == null) {
// Looper.prepare();
// }
// if(time!=null&&time.length>0)
// {
// toast.setDuration(time[0]);
// mhandler.postDelayed(r, time[0]);
// }
// else
// {
// mhandler.postDelayed(r, 1000);
// }
Toast.makeText(context, tvString, Toast.LENGTH_SHORT).show();
}
}