android 在子线程中使用Toast.makeText()及自定义show Toast

//在toas初始化t前后加上:(前)Looper.prepare();(后)Looper.loop();即可,非常好用

	Looper.prepare();
	 if (url!=null){
	         Toast toast = Toast.makeText(context, content, Toast.LENGTH_SHORT);

		//ToastUtils.newToast(context,"保存成功");
 	}else {
		        Toast toast = Toast.makeText(context, content, Toast.LENGTH_SHORT);

		//ToastUtils.newToast(context,"保存失败");
	 }
 Looper.loop();


自定义:

    public void showToast(String msg) {
        if (toast == null) {
            toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
        } else {
            toast.setText(msg);
        }
        toast.show();
    }

你可能感兴趣的:(android 在子线程中使用Toast.makeText()及自定义show Toast)