界面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. 本机操作Excel文件提示错误:未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序。

    解决办法是: 选择项目-->右键"属性"-->生成-->目标平台-->选择X86或者首选32位

  2. The Grove(poj 3182)

    题意:一个n*m(n,m<=50)的矩阵有一片连着的树林,Bessie要从起始位置出发绕林子一圈再回来,每次只能向横着.竖着或斜着走一步.问最少需多少步才能完成. /* 如果我们用搜索来写的话, ...

  3. 洛谷P2814 家谱(gen)

    题目背景 现代的人对于本家族血统越来越感兴趣. 题目描述 给出充足的父子关系,请你编写程序找到某个人的最早的祖先. 输入输出格式 输入格式: 输入由多行组成,首先是一系列有关父子关系的描述,其中每一组 ...

  4. 跨多种环境部署 Gearman -改善应用程序性能和降低服务器负载

    您可能想要将工作扩散到一个大型机器群体中,或者想要在不同语言和环境之间共享功能,那么开放源码的 Gearman 服务可以让您轻松地将工作分布到网络中的其他机器.本文将介绍 Gearman 的一些典型应 ...

  5. Mysqli的常用函数

    Mysqli的常用函数 连接数据库: $res = @mysqli_connect($host,$username,$pass,$db_name); if (mysqli_connect_errno( ...

  6. 2018 百度之星 初赛 第六题 HDU6349

    三原色图  Accepts: 281  Submissions: 1261  Time Limit: 1500/1000 MS (Java/Others)  Memory Limit: 262144/ ...

  7. RedirectAttributes

    RedirectAttributes是Spring mvc 3.1版本之后出来的一个功能,专门用于重定向之后还能带参数跳转的 他有两种带参的方式: 第一种:  attr.addAttribute(&q ...

  8. 动态规划: HDU 1789Doing Homework again

    Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of h ...

  9. P1455 搭配购买

    洛谷——P1455 搭配购买 题目描述 明天就是母亲节了,电脑组的小朋友们在忙碌的课业之余挖空心思想着该送什么礼物来表达自己的心意呢?听说在某个网站上有卖云朵的,小朋友们决定一同前往去看看这种神奇的商 ...

  10. 生产环境之Nginx高可用方案

    准备工作: 192.168.16.128 192.168.16.129 两台虚拟机.安装好Nginx 安装Nginx 更新yum源文件: rpm -ivh http://nginx.org/packa ...