ToastUtil

将Toast的调用封装成一个接口,写在一个公共的类当中

public class Util {

    private static Toast toast;

    public static void showToast(Context context, 
        String content) {
        if (toast == null) {
            toast = Toast.makeText(context,
                         content, 
                         Toast.LENGTH_SHORT);
        } else {
            toast.setText(content);
        }
        toast.show();
    }

}

调用的时候,只需要把Context对象和Toast要显示的内容传进来就可以了

  Util.showToast(context, "things happened");
posted @ 2017-09-22 13:32  yl007  阅读(142)  评论(0编辑  收藏  举报