最近在做一个项,有一个收藏的功能。后来看到了一点资讯的收藏动画,感觉不错,所有自己就实现了一下。
这是效果:
附上完整的代码,其中Animation_Toast为动画:
<div ><span ></span></div><pre name="code" >public class CollectToast { private static CollectToast toastCollectSucceed = null; private Toast toast = null; private TextVIEw text; private CollectToast() {} /** * 单例模式 * * @return */ public static CollectToast createtoast() { if (toastCollectSucceed == null) { toastCollectSucceed = new CollectToast(); } return toastCollectSucceed; } /** * 显示Toast * * @param context * @param root * @param tvString * @param result 是否成功 */ 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); 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; } /** * 反射字段 * * @param object 要反射的对象 * @param fIEldname 要反射的字段名称 * @return * @throws NoSuchFIEldException * @throws illegalaccessexception */ 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>总结
以上是内存溢出为你收集整理的Android仿一点资讯收藏Toast动画效果全部内容,希望文章能够帮你解决Android仿一点资讯收藏Toast动画效果所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)