Android 使用大号的通知

来源:互联网 发布:从笔记本cpu编号知型号 编辑:程序博客网 时间:2024/04/27 14:24

Notification 一般是两个形式出现的:

一种是普通形式

这里写图片描述

一种是bigView形式:

这里写图片描述

但是 big View 只在Notification扩展的时候显示,也就是说, 只在 此Notification 在drawer的最上面,或者是用户点击之后,才会扩展。

使用 BigView 的目的在于,让用户不需要打开 应用,就可以完成交互


构造一个Bigview (闹钟样例)

构造 忽略稍后 两个将会出现在 bigview中的按钮

Intent dismissIntent = new Intent(this, PingService.class);dismissIntent.setAction(CommonConstants.ACTION_DISMISS);PendingIntent piDismiss = PendingIntent.getService(this, 0, dismissIntent, 0);Intent snoozeIntent = new Intent(this, PingService.class);snoozeIntent.setAction(CommonConstants.ACTION_SNOOZE);PendingIntent piSnooze = PendingIntent.getService(this, 0, snoozeIntent, 0);

添加到你的通知中去

// Constructs the Builder object.NotificationCompat.Builder builder =        new NotificationCompat.Builder(this)        .setSmallIcon(R.drawable.ic_stat_notification)        .setContentTitle(getString(R.string.notification))        .setContentText(getString(R.string.ping))        .setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission        /*         * Sets the big view "big text" style and supplies the         * text (the user's reminder message) that will be displayed         * in the detail area of the expanded notification.         * These calls are ignored by the support library for         * pre-4.1 devices.         */        .setStyle(new NotificationCompat.BigTextStyle()                .bigText(msg))        .addAction (R.drawable.ic_stat_dismiss,                getString(R.string.dismiss), piDismiss)        .addAction (R.drawable.ic_stat_snooze,                getString(R.string.snooze), piSnooze);
0 0
原创粉丝点击