界面Layout:  customnotice.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp">
<ImageView
android:id="@+id/poster"
android:layout_width="108dp"
android:layout_height="match_parent"
android:background="@drawable/poster"
android:contentDescription="这是专辑图片" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@android:color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:paddingLeft="9dp"
android:paddingRight="9dp"
android:paddingTop="9dp">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:text="从前的我-陈洁仪"
android:textColor="#000000"
android:textSize="16sp" />
<ImageView
android:id="@+id/exit"
android:layout_width="64dp"
android:layout_height="45dp"
android:layout_gravity="center_vertical"
android:src="@drawable/exit" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/left" />
<ImageView
android:id="@+id/on"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/on" />
<ImageView
android:id="@+id/right"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/right" />
<ImageView
android:id="@+id/love"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/love" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

 发送通知逻辑代码:

              // 1、创建 manger
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// 2、 创建 NotificationChannel(通知渠道) android 新特性
NotificationChannel channel = new NotificationChannel("1",
"Channel1", NotificationManager.IMPORTANCE_DEFAULT);
channel.enableLights(true); //是否在桌面icon右上角展示小红点
channel.setLightColor(Color.GREEN); //小红点颜色
channel.setShowBadge(true); //是否在久按桌面图标时显示此渠道的通知
notificationManager.createNotificationChannel(channel);
// 3、 创建 Builder
NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this,"1");
builder.setSmallIcon(R.drawable.music);
builder.setContentTitle("title");
builder.setContentText("content title");
// builder.setNumber(3); //久按桌面图标时允许的此条通知的数量
// 4、 绑定 layout
RemoteViews rv = new RemoteViews(getPackageName(),R.layout.customnotice);              /* 更改视图内容 */
//rv.setTextViewText(R.id.title,"泡沫");//修改自定义View中的歌名
//修改自定义View中的图片(两种方法)
//rv.setImageViewResource(R.id.iv,R.mipmap.ic_launcher);
// rv.setImageViewBitmap(R.id.poster, BitmapFactory.decodeResource(getResources(),R.drawable.music)); builder.setContent(rv);
// 5、 创建 notification
Notification notification = builder.build();
// 6、发送通知
notificationManager.notify(0,notification); // //删除NotificationChannel
// NotificationChannel mChannel =manager.getNotificationChannel(id);
// manager.deleteNotificationChannel(mChannel);

 界面效果:

android8 Notification的更多相关文章

  1. Android8.1 SystemUI源码分析之 Notification流程

    代码流程 1.先看UI显示,StatuBar加载 CollapsedStatusBarFragment 替换 status_bar_container(状态栏通知显示区域) SystemUI\src\ ...

  2. Android Notification通知栏的使用,通知栏在Android8.0系统不显示的问题;

    1.正常使用通知栏: /** * 创建通知栏管理工具 */ NotificationManager notificationManager = (NotificationManager) getSys ...

  3. Android8.0通知

    android里面经常会使用Notification来显示通知的消息,一般使用NotificationManager来创建通知消息 NotificationManager manger = (Noti ...

  4. Android8.1 MTK平台 SystemUI源码分析之 网络信号栏显示刷新

    SystemUI系列文章 Android8.1 MTK平台 SystemUI源码分析之 Notification流程 Android8.1 MTK平台 SystemUI源码分析之 电池时钟刷新 And ...

  5. Android8.1 SystemUI源码分析之 电池时钟刷新

    SystemUI源码分析相关文章 Android8.1 SystemUI源码分析之 Notification流程 分析之前再贴一下 StatusBar 相关类图 电池图标刷新 从上篇的分析得到电池图标 ...

  6. Android8.0 后台服务保活的一种思路

    原文地址:Android8.0 后台服务保活的一种思路 | Stars-One的杂货小窝 项目中有个MQ服务,需要一直连着,接收到消息会发送语音,且手机要在锁屏也要实现此功能 目前是使用广播机制实现, ...

  7. Android Notification使用

    一 Notification的类别 1.状态栏和抽屉式通知 //获取NotificationManager对象 val notificationManager = getSystemService(N ...

  8. Android Notification 详解(一)——基本操作

    Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...

  9. Android Notification 详解——基本操作

    Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...

随机推荐

  1. 【HIHOCODER 1478】 水陆距离(BFS)

    描述 给定一个N x M的01矩阵,其中1表示陆地,0表示水域.对于每一个位置,求出它距离最近的水域的距离是多少. 矩阵中每个位置与它上下左右相邻的格子距离为1. 输入 第一行包含两个整数,N和M. ...

  2. 【转】如何在命令行脚本中启动带参数的Windows服务

    我们有一个自己编写的Windows服务,我们希望该服务在启动时可以根据用户输入的参数实现不同的功能. 要实现这样的需求并不是很难,下面这个例子我用来示范如何编写该服务 using System; us ...

  3. iframe in ipad safari

    http://developer.apple.com/library/safari/#documentation/appleapplications/reference/safariwebconten ...

  4. ms sqlserver数据库建索引

    索引分类:从物理结构上可分为两种:聚集索引和非聚集索引 (此外还有空间索引.筛选索引.XML索引) 因为聚集索引是索引顺序与物理存储顺序一致,所以只能建一个. 聚集索引就是把数据按主键顺序存储: 因为 ...

  5. Heredoc和Nowdoc

    就象heredoc结构类似于双引号字符串,Nowdoc结构是类似于单引号字符串的.Nowdoc结构很象heredoc结构,但是 nowdoc不进行解析操作 . 这种结构很适合用在不需要进行转义的PHP ...

  6. HDU 6278 主席树(区间第k大)+二分

    Just h-index Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)To ...

  7. 七天从零基础学习android(1)--配置环境

    在写这篇文的时候android开发经验还是0,是一个萌新,这是一篇记录一个萌新从零android编程基础到能编写一个记账本的开发过程(至少我是这样美好的希望着的) 首先因为是没有开发基础的,直接上百度 ...

  8. Defcon 23最新开源工具NetRipper代码分析与利用

    0×01 研究背景 在分析了俄罗斯人被曝光的几个银行木马的源码后,发现其大多均存在通过劫持浏览器数据包来获取用户个人信息的模块,通过截获浏览器内存中加密前或解密后的数据包来得到数据包的明文数据.在De ...

  9. TUN/TAP区别

    在计算机网络中,TUN与TAP是操作系统内核中的虚拟网络设备.不同于普通靠硬件网路板卡实现的设备,这些虚拟的网络设备全部用软件实现,并向运行于操作系统上的软件提供与硬件的网络设备完全相同的功能. TA ...

  10. Promise编程规范

    参考: http://www.cnblogs.com/dojo-lzz/p/4340897.html 闲话promise机制  http://www.cnblogs.com/lvdabao/p/es6 ...