AndroidUtils——ToastUtils
来源:互联网 发布:淮北微商自然知彼 编辑:程序博客网 时间:2024/06/07 00:11
import android.support.annotation.IdRes;import android.support.annotation.LayoutRes;import android.support.annotation.StringRes;import android.view.View;import android.widget.TextView;import android.widget.Toast;import com.feathers.utils.app.AppContext;/** * Toast统一管理类 * Created by feathers on 16-9-23. * @author feathers */public class ToastUtils { private ToastUtils() { throw new UnsupportedOperationException("cannot be instantiated"); } public static boolean isShow = true; /** * 短时间显示Toast * * @param message */ public static void showShort(CharSequence message) { if (isShow) Toast.makeText(AppContext.getContext(), message, Toast.LENGTH_SHORT).show(); } /** * 短时间显示Toast * * @param message */ public static void showShort(@StringRes int message) { if (isShow) Toast.makeText(AppContext.getContext(), message, Toast.LENGTH_SHORT).show(); } /** * 长时间显示Toast * * @param message */ public static void showLong(CharSequence message) { if (isShow) Toast.makeText(AppContext.getContext(), message, Toast.LENGTH_LONG).show(); } /** * 长时间显示Toast * * @param message */ public static void showLong(@StringRes int message) { if (isShow) Toast.makeText(AppContext.getContext(), message, Toast.LENGTH_LONG).show(); } /** * 自定义显示Toast时间 * * @param message * @param duration */ public static void show(CharSequence message, int duration) { if (isShow) Toast.makeText(AppContext.getContext(), message, duration).show(); } /** * 自定义显示Toast时间 * * @param message * @param duration */ public static void show(@StringRes int message, int duration) { if (isShow) Toast.makeText(AppContext.getContext(), message, duration).show(); } /** * 展示一个特定布局的Toast(短时间) * * @param message 要展示的信息 * @param viewResLayout 整个Toast的布局 * @param tvResId 要展示message的textView(或者是他的子类),注意:参数3不会主动将view加入到toast layout中 */ public static void showShort(CharSequence message, @LayoutRes int viewResLayout, @IdRes int tvResId) { View v = ResourceUtils.inflate(viewResLayout); Toast toast = new Toast(AppContext.getContext()); TextView tv = (TextView) v.findViewById(tvResId); tv.setText(message); toast.setView(v); toast.setDuration(Toast.LENGTH_SHORT); toast.show(); } /** * 展示一个特定布局的Toast(长) * * @param message 要展示的信息 * @param viewResLayout 整个Toast的布局 * @param tvResId 要展示message的textView(或者是他的子类),注意:参数3不会主动将view加入到toast layout中 */ public static void showLong(CharSequence message, @LayoutRes int viewResLayout, @IdRes int tvResId) { View v = ResourceUtils.inflate(viewResLayout); Toast toast = new Toast(AppContext.getContext()); TextView tv = (TextView) v.findViewById(tvResId); tv.setText(message); toast.setView(v); toast.setDuration(Toast.LENGTH_LONG); toast.show(); } /** * 展示一个特定布局的Toast(短时间) * * @param message 要展示的信息 * @param viewResLayout 整个Toast的布局 * @param tvResId 要展示message的textView(或者是他的子类),注意:参数3不会主动将view加入到toast layout中 */ public static void showShort(@StringRes int message, @LayoutRes int viewResLayout, @IdRes int tvResId) { View v = ResourceUtils.inflate(viewResLayout); Toast toast = new Toast(AppContext.getContext()); TextView tv = (TextView) v.findViewById(tvResId); tv.setText(message); toast.setView(v); toast.setDuration(Toast.LENGTH_SHORT); toast.show(); } /** * 展示一个特定布局的Toast(长) * * @param message 要展示的信息 * @param viewResLayout 整个Toast的布局 * @param tvResId 要展示message的textView(或者是他的子类),注意:参数3不会主动将view加入到toast layout中 */ public static void showLong(@StringRes int message, @LayoutRes int viewResLayout, @IdRes int tvResId) { View v = ResourceUtils.inflate(viewResLayout); Toast toast = new Toast(AppContext.getContext()); TextView tv = (TextView) v.findViewById(tvResId); tv.setText(message); toast.setView(v); toast.setDuration(Toast.LENGTH_LONG); toast.show(); } /** * 展示一个特定布局的Toast(短时间) * * @param message 要展示的信息 * @param view toast的布局 */ public static void showShort(CharSequence message, View view) { Toast toast = new Toast(AppContext.getContext()); toast.setView(view); toast.setDuration(Toast.LENGTH_SHORT); toast.show(); } /** * 展示一个特定布局的Toast(长) * * @param message 要展示的信息 * @param view Toast的布局 */ public static void showLong(CharSequence message, View view) { Toast toast = new Toast(AppContext.getContext()); toast.setView(view); toast.setDuration(Toast.LENGTH_LONG); toast.show(); } /** * 展示一个特定布局的Toast(短时间) * * @param message 要展示的信息 * @param view toast的布局 */ public static void showShort(@StringRes int message, View view) { Toast toast = new Toast(AppContext.getContext()); toast.setView(view); toast.setDuration(Toast.LENGTH_SHORT); toast.show(); } /** * 展示一个特定布局的Toast(长) * * @param message 要展示的信息 * @param view Toast的布局 */ public static void showLong(@StringRes int message, View view) { Toast toast = new Toast(AppContext.getContext()); toast.setView(view); toast.setDuration(Toast.LENGTH_LONG); toast.show(); }}
0 0
- AndroidUtils——ToastUtils
- AndroidUtils——LogUtils
- AndroidUtils——DensityUtils
- Toast管理——ToastUtils
- 工具类——吐司ToastUtils封装
- ToastUtils
- ToastUtils
- ToastUtils
- ToastUtils
- ToastUtils
- Android ToastUtils
- ToastUtils记录
- Android工具包AndroidUtils
- AndroidUtils一些类方法
- Android 定义全局 ToastUtils
- ToastUtils工具类
- ToastUtils工具类
- ToastUtils工具类
- C指针有感
- Java集合源码解析(三)HashMap源码解析
- UVALive - 4287 Proving Equivalences
- LinkedHashMap源码分析与LRU实现
- open系统调用的O_CREAT和O_EXCL
- AndroidUtils——ToastUtils
- Java集合源码解析(四)TreeMap源码解析
- Java集合源码解析(五)HashSet源码解析
- Java Set&HashSet
- 区间平均值(逆序对)
- Android动画全解析(二)
- 南阳oj 14 会场安排问题
- mysql和oracle的区别
- 使用OkHttp进行网络同步异步操作