最近在做一个项,有一个收藏的功能。后来看到了一点资讯的收藏动画,感觉不错,所有自己就实现了一下。这是效果:附上完整的代码,其中Animation_Toast为动画:<div ><span ></span>
最近在做一个项,有一个收藏的功能。后来看到了一点资讯的收藏动画,感觉不错,所有自己就实现了一下。
这是效果:
附上完整的代码,其中Animation_Toast为动画:
<div ><span ></span></div><pre name="code" class="java">public class CollectToast { private static CollectToast toastCollectSucceed = null; private Toast toast = null; private TextView text; private CollectToast() {} public static CollectToast createToast() { if (toastCollectSucceed == null) { toastCollectSucceed = new CollectToast(); } return toastCollectSucceed; } public Toast showToast(Context context, ViewGroup root, String tvString, int duration, boolean result) { toast = null; int styleId = R.style.Animation_Toast; if (toast == null) { View layout = LayoutInflater.from(context).inflate(R.layout.toast_collect_layout, root); text = (TextView) layout.findViewById(R.id.title_tv); ImageView imageView = (ImageView) layout.findViewById(R.id.iv); if (result) imageView.setBackgroundDrawable(DrawableUtil.getImageDrawable(context, R.mipmap.doneicon_popup_textpage)); else imageView.setBackgroundDrawable(DrawableUtil.getImageDrawable(context, R.mipmap.close_popup_textpage)); text.setText(tvString); toast = new Toast(context); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(duration); toast.setView(layout); toast.show(); } else { text.setText(tvString); toast.show(); } //通过反射给Toast设置动画 try { Object mTN = null; mTN = getField(toast, "mTN"); if (mTN != null) { Object mParams = getField(mTN, "mParams"); if (mParams != null && mParams instanceof WindowManager.LayoutParams) { WindowManager.LayoutParams params = (WindowManager.LayoutParams) mParams; params.windowAnimations = styleId; } } } catch (Exception e) { e.printStackTrace(); } return toast; } private static Object getField(Object object, String fieldName) throws NoSuchFieldException, IllegalAccessException { Field field = object.getClass().getDeclaredField(fieldName); if (field != null) { field.setAccessible(true); return field.get(object); } return null; } }</pre><br> <div ><span ></span></div> <pre></pre> <br> <br>
--结束END--
本文标题: Android仿一点资讯收藏Toast动画效果
本文链接: https://lsjlt.com/news/222713.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0