歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android自定義Notification

Android自定義Notification

日期:2017/3/1 11:09:07   编辑:Linux編程
Notification是一種讓你的應用程序在不使用Activity的情況下警示用戶,Notification是看不見的程序組件警示用戶有需要注意的事件發生的最好途徑。

作為UI部分,Notification對移動設備來說是最適合不過的了。用戶可能隨時都帶著手機在身邊。一般來說,用戶會在後台打開幾個程序,但不會注意它們。在這樣的情形下,當發生需要注意的事件時,能夠通知用戶是很重要的。

Notification由NotificationManger統一管理,目前包含的能力有:

?創建一個狀態條圖標。

?在擴展的狀態條窗口中顯示額外的信息(和啟動一個Intent)。

?閃燈或LED。

?電話震動。

?發出聽得見的警告聲(鈴聲,保存的聲音文件)。

自定義Notification效果圖:

自定義的布局文件:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3. xmlns:Android="http://schemas.android.com/apk/res/android"
  4. android:orientation="vertical"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent">
  7. <TextView
  8. android:id="@+id/tv_rv"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:text="haha"
  12. />
  13. <ProgressBar
  14. style="@android:style/Widget.ProgressBar.Horizontal"
  15. android:id="@+id/pb_rv"
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. />
  19. </LinearLayout>
Copyright © Linux教程網 All Rights Reserved