您的位置:首页 > 其它

Notification and Toast comments

2015-10-30 17:13 351 查看
1。 Notification. 对用户进行状态的提示和允许用户进行动作的选择。

Notification area & Notification Draw

API20 支持 heads-up notification

API21 支持Lock Screen Notification

有以下显示形式

1。最简单的icon,title和content text

2。系统定义的style
NotificationCompat.BuildersetStyle(NotificationCompat.Style style)
3。可以有用户定义view

public NotificationCompat.BuildersetContent(RemoteViews views)

4。可以放置进度条

...
mNotifyManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(this);
mBuilder.setContentTitle("Picture Download")
.setContentText("Download in progress")
.setSmallIcon(R.drawable.ic_notification);
// Start a lengthy operation in a background thread
new Thread(
new Runnable() {
@Override
public void run() {
int incr;
// Do the "lengthy" operation 20 times
for (incr = 0; incr <= 100; incr+=5) {
// Sets the progress indicator to a max value, the
// current completion percentage, and "determinate"
// state
mBuilder.setProgress(100, incr, false);
// Displays the progress bar for the first time.
mNotifyManager.notify(0, mBuilder.build());
// Sleeps the thread, simulating an operation
// that takes time
try {
// Sleep for 5 seconds
Thread.sleep(5*1000);
} catch (InterruptedException e) {
Log.d(TAG, "sleep failure");
}
}
// When the loop is finished, updates the notification
mBuilder.setContentText("Download complete")
// Removes the progress bar
.setProgress(0,0,false);
mNotifyManager.notify(ID, mBuilder.build());
}
}
// Starts the thread by calling the run() method in its Runnable
).start();

5。可以放置action

NotificationCompat.BuilderaddAction(int icon,CharSequence title,PendingIntent intent)
1。创建

NotificationCompat.Builder


2。发送

mNotificationManager.notify


3。取消

mNotificationManager.cancel
取消,
也可以设置点击取消


可以按系统类别归类

可以设置优先级

可以设用户(另一中归类的方法)

在发送时给一个id,随后可以用此ID更新。Notification是一个存储在系统的token,类是pendingitent

Toast

可以设置用户自定义view

可以自定义位置
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: