您的位置:首页 > 其它

Toast简单的工具类

2016-05-26 13:50 239 查看
import android.widget.Toast;

/**

 * Created by chao0 on 2016/5/26.

 */

public class ToastUtils {

    private static Toast toast;

    //双重判断确保整个程序只有一个吐司

    public static void toastShow(String text){

        if (toast==null){

            synchronized (ToastUtils.class){

                if (toast==null){

                    toast=Toast.makeText(AppUtils.getBaseContext(),text,Toast.LENGTH_SHORT);

                }

            }

        }else{

            toast.cancel();

            toast=Toast.makeText(AppUtils.getBaseContext(),text,Toast.LENGTH_SHORT);

        }

        toast.show();

    }

    //运行在工作线程的吐司

    public static void showWorkThread(final String text){

        ThreadPoolUtils.runTaskOnUIThread(new Runnable() {

            @Override

            public void run() {

                toastShow(text);

            }

        });

    }

    //运行在ui线程的吐司

    public static void showUIThread(String text){

        toastShow(text);

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: