Android仿一點資訊收藏Toast動畫效果
更新時間:2017年06月22日 15:31:28 作者:wangw-csdn
這篇文章主要介紹了Android仿一點資訊收藏Toast動畫效果,效果非常不錯,具有參考借鑒價值,需要的朋友可以參考下
最近在做一個項,有一個收藏的功能。后來看到了一點資訊的收藏動畫,感覺不錯,所有自己就實現(xiàn)了一下。
這是效果:
附上完整的代碼,其中Animation_Toast為動畫:
<div style="text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;"></span></div><pre name="code" class="java">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, 0); toast.setDuration(duration); toast.setView(layout); toast.show(); } else { text.setText(tvString); toast.show(); } //通過反射給Toast設(shè)置動畫 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 style="text-align:left"><span style="font-family:Arial,Helvetica,sans-serif"></span></div> <pre></pre> <br> <br>
相關(guān)文章
Kotlin?協(xié)程異步熱數(shù)據(jù)流的設(shè)計與使用講解
這篇文章主要為大家介紹了Kotlin?協(xié)程協(xié)程異步熱數(shù)據(jù)流的設(shè)計與使用講解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-09-09Android編程入門之HelloWorld項目目錄結(jié)構(gòu)分析
這篇文章主要介紹了Android編程入門之HelloWorld項目目錄結(jié)構(gòu)分析,較為詳細(xì)的分析了Android項目的目錄結(jié)構(gòu)與具體作用,需要的朋友可以參考下2015-12-12如何通過Battery Historian分析Android APP耗電情況
Android 從兩個層面統(tǒng)計電量的消耗,分別為軟件排行榜及硬件排行榜。它們各有自己的耗電榜單,軟件排行榜為機器中每個 App 的耗電榜單,硬件排行榜則為各個硬件的耗電榜單。這兩個排行榜的統(tǒng)計是互為獨立,互不干擾的2021-06-06Android系統(tǒng)添加自定義鼠標(biāo)樣式通過按鍵切換實例詳解
在本篇文章里小編給大家整理的是關(guān)于Android系統(tǒng)添加自定義鼠標(biāo)樣式通過按鍵切換實例詳解內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。2019-11-11