Notification是一种具有全局效果的通知,它展示在屏幕的顶端,首先会表现为一个图标的形式,当用户向下滑动的时候,展示出通知具体的内容。
它是一种让你的应用程序在没有开启情况下或在后台运行警示用户。它是看不见的程序组件(Broadcast Receiver,Service和不活跃的Activity)警示用户有需要注意的事件发生的最好途径。
状态栏和状态条
状态条就是手机屏幕最上方的一个条形状的区域;
在状态条有好多信息量:比如usb连接图标,手机信号图标,电池电量图标,时间图标等等;
状态栏就是手从状态条滑下来的可以伸缩的view;
在状态栏中一般有两类(使用FLAG_标记):
(1)正在进行的程序
(2)通知事件
大概来描述创建一个Notification传送的信息有
一个状态条图标
在拉伸的状态栏窗口中显示带有大标题,小标题,图标的信息,并且有处理该点击事件:
比如调用该程序的入口类
闪光,LED,或者震动
内容信息:
实例化一个Notification.Builder对象;
注意:在android:minSdkVersion <16以下时,可以使用
NotificationCompat.Builder创建。
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:layout_width="match_parent" 3 android:layout_height="match_parent" 4 android:orientation="vertical" > 5 6 <Button 7 android:layout_width="match_parent" 8 android:layout_height="wrap_content" 9 android:onClick="sendNotification" 10 android:text="发送通知" /> 11 12 <Button 13 android:layout_width="match_parent" 14 android:layout_height="wrap_content" 15 android:onClick="clearNotification" 16 android:text="清除通知" /> 17 18 <Button 19 android:layout_width="match_parent" 20 android:layout_height="wrap_content" 21 android:onClick="diyNotification" 22 android:text="自定义通知" /> 23 24 </LinearLayout>