国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android仿一點資訊收藏Toast動畫效果

2019-12-12 02:37:19
字體:
來源:轉載
供稿:網友

最近在做一個項,有一個收藏的功能。后來看到了一點資訊的收藏動畫,感覺不錯,所有自己就實現了一下。

這是效果:

附上完整的代碼,其中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設置動畫     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> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 榕江县| 安塞县| 普宁市| 郴州市| 威海市| 绵竹市| 保康县| 左云县| 宜阳县| 石渠县| 育儿| 门源| 张掖市| 赤峰市| 香港 | 商洛市| 襄樊市| 武胜县| 宣化县| 科尔| 赣榆县| 报价| 夏邑县| 女性| 乌拉特前旗| 青川县| 喀什市| 新余市| 加查县| 嘉峪关市| 本溪市| 长岛县| 延津县| 阳信县| 沁阳市| 南木林县| 肇州县| 镇远县| 四子王旗| 册亨县| 九龙坡区|