溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Android應(yīng)用中怎么實(shí)現(xiàn)通知欄閃動效果

發(fā)布時間:2020-11-24 15:51:14 來源:億速云 閱讀:151 作者:Leah 欄目:移動開發(fā)

Android應(yīng)用中怎么實(shí)現(xiàn)通知欄閃動效果?相信很多沒有經(jīng)驗(yàn)的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

顯示通知代碼:

private void showNotification(Context ctx, String url) {
    Notification n = new Notification();
    n.flags |= Notification.FLAG_SHOW_LIGHTS;
    n.flags |= Notification.FLAG_AUTO_CANCEL;
    n.defaults = Notification.DEFAULT_SOUND;
    n.icon = R.drawable.ic_launcher;
    n.when = System.currentTimeMillis();
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClassName(ctx.getPackageName(), MainActivity.class.getName());
    PendingIntent pi = PendingIntent.getActivity(ctx, 0, intent, 0);
    n.setLatestEventInfo(ctx, "title", "summary", pi);
    NotificationManager manager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(0, n);
}

你要設(shè)置圖片閃動的話,這個沒有api,你只能設(shè)置具有動畫效果的圖片,替換上面代碼中的n.icon,google的下載通知算是一種動畫,他的實(shí)現(xiàn)是:

<animation-list
  xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
  <item android:drawable="@drawable/stat_sys_download_anim0" android:duration="200" />
  <item android:drawable="@drawable/stat_sys_download_anim1" android:duration="200" />
  <item android:drawable="@drawable/stat_sys_download_anim2" android:duration="200" />
  <item android:drawable="@drawable/stat_sys_download_anim3" android:duration="200" />
  <item android:drawable="@drawable/stat_sys_download_anim4" android:duration="200" />
  <item android:drawable="@drawable/stat_sys_download_anim5" android:duration="200" />
</animation-list>

看完上述內(nèi)容,你們掌握Android應(yīng)用中怎么實(shí)現(xiàn)通知欄閃動效果的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI