源码及安装文件下载方式:MyToast.zip
实现效果图如下:
自定义 Toast 实现核心代码:
package cn.sunzn.mytoast; import android.content.Context; import android.view.View; import android.widget.TextView; import android.widget.Toast; public class MyToast { public static void showToast(Context context, String content) { Toast toast = new Toast(context); View view = View.inflate(context, R.layout.mytoast, null); TextView tv_toast = (TextView) view.findViewById(R.id.tv_toast); tv_toast.setText(content); toast.setView(view); toast.setDuration(Toast.LENGTH_LONG); toast.show(); } }