Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 狀態列通知 Status Bar Notification

編輯:關於 Android 開發

Android 狀態列通知 Status Bar Notification

Android 通知主要有 Toast、Dialog 與 Status Bar 三種形式。狀態列通知需要 NotificationManager 與 Notification 兩個核心類別。NotificationManager 是系統服務,可透過 getSystemService 取得;Notification 則負責描述通知的圖示、標題、內容與點擊行為。

基本通知會設定 icon、tickerText 與 when,並透過 PendingIntent 指定點擊後要開啟的 Activity。若需要自訂版面,可使用 RemoteViews 搭配自訂 notification_layout,再設定 contentView 與 contentIntent。若希望點擊後自動關閉通知,可加上 FLAG_AUTO_CANCEL。

若出現 Couldn't expand RemoteViews 錯誤,通常代表自訂版面使用了 RemoteViews 不支援的元件,或缺少必要屬性,需逐一檢查。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved