Notification and Toast comments

1。 Notification. 对用户进行状态的提示和允许用户进行动作的选择。


Notification area & Notification Draw

API20 支持 heads-up notification

API21 支持Lock Screen Notification

有以下显示形式

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

2。系统定义的style

NotificationCompat.Builder setStyle( 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.Builder addAction(int icon, CharSequence title, PendingIntent intent)


1。创建

NotificationCompat.Builder

2。发送

mNotificationManager.notify

3。取消

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


可以按系统类别归类

可以设置优先级

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


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



Toast


可以设置用户自定义view

可以自定义位置


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值