admin
2021-05-28 98cc34dbca6d6218ec5e72baffda2d3a1dd72a55
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
package com.tejia.lijin.app.util;
 
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
 
import com.tejia.lijin.app.R;
 
/**
 * 居中展示Toast
 */
public class CenterToast {
 
    /**
     * 金币获取Toast
     *
     * @param context
     * @param desc    描述
     * @param goldNum 金币数量
     */
    public static void gainGoldShow(Context context, String desc, String goldNum) {
        // 自定义土司显示位置
        // 创建土司
        Toast toast = new Toast(context);
        // 找到toast布局的位置
        View view = View.inflate(context, R.layout.toast_gain_gold, null);
        TextView tv_desc = view.findViewById(R.id.tv_desc);
        TextView tv_gold_num = view.findViewById(R.id.tv_gold_num);
        tv_desc.setText(desc);
        tv_gold_num.setText(goldNum);
        // 设置toast文本,把设置好的布局传进来
        toast.setView(view);
        // 设置土司显示在屏幕的位置
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        // 显示土司
        toast.show();
    }
}