Android自定义Toast样式

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

你可能感兴趣的:(Android自定义Toast样式)