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();
|
}
|
}
|