Android自定义Toast样式

来源:互联网 发布:pp助手mac安卓手机版 编辑:程序博客网 时间:2024/05/23 14:24
Android自定义Toast样式
public class ToastUtils {    private static Toast toast;    private static TextView textView;    public static void showToast(Context context, String text) {        if (toast == null) {            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);            View view = inflater.inflate(R.layout.item_toast_bg, null);            textView = (TextView) view.findViewById(R.id.tv_toast_text);            textView.getLayoutParams().width = Utils.getWindowWidth(context);            toast = new Toast(context);            toast.setGravity(Gravity.BOTTOM, 0, 0);//如果不设置剧中方式,使用系统默认的吐司位置            toast.setDuration(Toast.LENGTH_SHORT);            toast.setView(view);        }        textView.setText(text);        toast.show();    }}  
原创粉丝点击