界面Layout:  customnotice.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="100dp">
 5     <ImageView
 6         android:id="@+id/poster"
 7         android:layout_width="108dp"
 8         android:layout_height="match_parent"
 9         android:background="@drawable/poster"
10         android:contentDescription="这是专辑图片" />
11     <LinearLayout
12         android:layout_width="match_parent"
13         android:layout_height="100dp"
14         android:background="@android:color/white"
15         android:orientation="vertical">
16         <LinearLayout
17             android:layout_width="match_parent"
18             android:layout_height="50dp"
19             android:orientation="horizontal"
20             android:paddingLeft="9dp"
21             android:paddingRight="9dp"
22             android:paddingTop="9dp">
23             <TextView
24                 android:id="@+id/title"
25                 android:layout_width="match_parent"
26                 android:layout_height="match_parent"
27                 android:layout_weight="1"
28                 android:ellipsize="end"
29                 android:gravity="center"
30                 android:singleLine="true"
31                 android:text="从前的我-陈洁仪"
32                 android:textColor="#000000"
33                 android:textSize="16sp" />
34             <ImageView
35                 android:id="@+id/exit"
36                 android:layout_width="64dp"
37                 android:layout_height="45dp"
38                 android:layout_gravity="center_vertical"
39                 android:src="@drawable/exit" />
40         </LinearLayout>
41         <LinearLayout
42             android:layout_width="match_parent"
43             android:layout_height="50dp"
44             android:gravity="center"
45             android:orientation="horizontal">
46             <ImageView
47                 android:id="@+id/left"
48                 android:layout_width="0dp"
49                 android:layout_height="wrap_content"
50                 android:layout_weight="1"
51                 android:src="@drawable/left" />
52             <ImageView
53                 android:id="@+id/on"
54                 android:layout_width="0dp"
55                 android:layout_height="wrap_content"
56                 android:layout_weight="1"
57                 android:src="@drawable/on" />
58             <ImageView
59                 android:id="@+id/right"
60                 android:layout_width="0dp"
61                 android:layout_height="wrap_content"
62                 android:layout_weight="1"
63                 android:src="@drawable/right" />
64             <ImageView
65                 android:id="@+id/love"
66                 android:layout_width="0dp"
67                 android:layout_height="wrap_content"
68                 android:layout_weight="1"
69                 android:src="@drawable/love" />
70         </LinearLayout>
71     </LinearLayout>
72 </LinearLayout>

 发送通知逻辑代码:

 1              // 1、创建 manger
 2                 NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 3                // 2、 创建  NotificationChannel(通知渠道) android 新特性
 4                 NotificationChannel channel = new NotificationChannel("1",
 5                         "Channel1", NotificationManager.IMPORTANCE_DEFAULT);
 6                 channel.enableLights(true); //是否在桌面icon右上角展示小红点
 7                 channel.setLightColor(Color.GREEN); //小红点颜色
 8                 channel.setShowBadge(true); //是否在久按桌面图标时显示此渠道的通知
 9                 notificationManager.createNotificationChannel(channel);
10                 //  3、 创建 Builder
11                 NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this,"1");
12                 builder.setSmallIcon(R.drawable.music);
13                 builder.setContentTitle("title");
14                 builder.setContentText("content title");
15 //                builder.setNumber(3); //久按桌面图标时允许的此条通知的数量
16                 // 4、 绑定  layout
17                 RemoteViews rv = new RemoteViews(getPackageName(),R.layout.customnotice);

             /* 更改视图内容  */
18                  //rv.setTextViewText(R.id.title,"泡沫");//修改自定义View中的歌名
19                   //修改自定义View中的图片(两种方法)
20                  //rv.setImageViewResource(R.id.iv,R.mipmap.ic_launcher);
21                   // rv.setImageViewBitmap(R.id.poster, BitmapFactory.decodeResource(getResources(),R.drawable.music));

22                 builder.setContent(rv);
23                 //  5、 创建  notification
24                 Notification notification = builder.build();
25                 // 6、发送通知
26                 notificationManager.notify(0,notification);
27
28 //                //删除NotificationChannel
29 //                NotificationChannel mChannel =manager.getNotificationChannel(id);
30 //                manager.deleteNotificationChannel(mChannel);

 界面效果:

转载于:https://www.cnblogs.com/the-wang/p/8909815.html

android8 Notification相关推荐

  1. android8 通知呼吸灯_Android8.0及以上的Notification

    这篇文章上次修改于 702 天前,可能其部分内容已经发生变化,如有疑问可询问作者. 在新版本上(Android8.0及以上)开发时,会遇到一些问题,比如,不显示通知,Notification 声音不可 ...

  2. 【android】Notification 和 Service的结合应用以及Notification在Android8.0之后的坑 Bad notification

    在结合<第一行代码>复习Service时踩到一个坑--notification 弹不出来,然后就crush掉了!!! 查阅相关资料发现是在Android8之后,notification很多 ...

  3. android8 通知呼吸灯_Android中通知Notification使用实例(振动、灯光、声音)

    本文实例讲解了通知Notification使用方法,此知识点就是用作通知的显示,包括振动.灯光.声音等效果,分享给大家供大家参考,具体内容如下 效果图: MainActivity: import ja ...

  4. Android之解决Android8.0手机(Notification)收不到自定义消息通知以及其它手机得到数据不同步

    1 问题 app,自定义消息通知的时候,在Android8.0手机上收不到通知 2 解决办法 NotificationManager需要创建NotificationChannel,然后调用create ...

  5. Android8.0以上的Service、Notification和广播适配问题

    8.0以上,广播必须添加componentName,否则会接收不到 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { //Compone ...

  6. android8 通知呼吸灯_android8 通知呼吸灯_说说8.0下 Android 通知(Notification)

    当运用程序不在前台运转,这时便借助关照( Notification )向用户发送少许提醒消息. 发出关照后,手机非常上方的状况栏中就会表现一个关照图标,下拉状况栏就会看到关照的细目. 1 根基用法 / ...

  7. android8 通知呼吸灯_说说8.0下 Android 通知(Notification)

    当运用程序不在前台运转,这时便借助关照( Notification )向用户发送少许提醒消息. 发出关照后,手机非常上方的状况栏中就会表现一个关照图标,下拉状况栏就会看到关照的细目. 1 根基用法 / ...

  8. Android8.0适配方案

    准备工作 将我们项目中的targetSdkVersion改为 26(8.0) 或者 27(8.1) 1运行时权限 首先引用官方的原文. https://developer.android.google ...

  9. Notification通知栏

    目录介绍 1.Notification简单概述 2.Notification通知用途 3.Notification的基本操作 3.1 Notification创建必要的属性 3.2 Notificat ...

最新文章

  1. HTTP 错误 404.0 - Not Found 您要找的资源已被删除、已更名或暂时不可用。
  2. Linux系统编程之--守护进程的创建和详解【转】
  3. oracle重新编译package,如何有效的编译数据库中的失效对象(Package,trigger等)
  4. [html] 如何让img自动适应div容器大小?
  5. POJ1430 Binary Stirling Numbers
  6. oracle11连12c报权限错误,关于Oracle12c连接报错的问题
  7. 为什要学习烹饪?学习烹饪迫在眉睫
  8. 坑爹的RockSaw和坑爹的windows7
  9. Qt使用flowlayout,使控件两端间距始终固定,垂直和水平间距相等
  10. mysql 重置密码_mysql忘记密码如何重置密码,以及修改root密码的三种方法
  11. Error setting null for parameter
  12. Hex Fiend很强大
  13. 如何拍出来好看的Vlog,必备小技能(六)?
  14. zookeeper从基础到精通
  15. 六级答案已出,计算机er要考多少分才能保个好学校?
  16. 今日芯声 | 微软 Xbox 老大:关闭游戏直播平台 Mixer,我没有遗憾
  17. 滤波算法一(C程序)
  18. 神经网络方法研究及应用,基于神经网络的控制
  19. 分享几个好看的Bootstrap后台管理响应式模板
  20. [蓝桥杯2015决赛]穿越雷区

热门文章

  1. python生成表格文件_python 读取excel文件生成sql文件实例详解
  2. 灰流丽能无效融合么_紫砂壶里的柴烧、捂灰、还原烧你能分清楚吗?一次性给你讲清楚...
  3. 进阶学习(3.10) Adapter Pattern 适配器模式
  4. 武汉网络推广介绍如何通过简化标题来提升主关键词排名?
  5. 浅析网站友情链接交换潜在问题有哪些?
  6. 企业网站SEO优化的四大原则
  7. docker omv 防火墙_我的软路由折腾之旅 篇三:在openmediavault上通过Docker实现OPENWRT旁路由功能...
  8. bootstrap4导航栏点击弹出表单_Bootstrap4从入门到精通
  9. 开发日记-20190914 关键词 汇编语言王爽版 第二章
  10. 可以通过shadowserver来查看开放的mdns(用以反射放大攻击)——中国的在 https://mdns.shadowserver.org/workstation/index.html...