遇到这种分析用什么实现的,肯定要祭出大杀器Android Device Monitor(AS在Tools->Android)
打开之后,选中连接的设备,然后点击小手机图标,即可导出UI层次图。
咱们来看下淘宝通知的UI层次图。
<img src="https://pic4.zhimg.com/08df4fad3cede85e28c121e820be7aff_b.png" data-rawwidth="1334" data-rawheight="768" class="origin_image zh-lightbox-thumb" width="1334" data-original="https://pic4.zhimg.com/08df4fad3cede85e28c121e820be7aff_r.png">看右侧,我擦嘞,居然是TextView,上面那个有个飞机的也是图片。看右侧,我擦嘞,居然是TextView,上面那个有个飞机的也是图片。
那是不是TextView的图文混排呢?
写段代码试下呗,测试发现没有卵用(具体为什么不可行,大家有兴趣可以分析下Android源码)。
那该怎么办,不知道你发现没有,淘宝使用的几乎都是emoji表情。
既然这样就好办了,在传入Notification的数据里面写入emoji数据试试。
果然,真的可以使用。而且,不限制放多少表情,客官随便放。
<img src="https://pic3.zhimg.com/fa46001dee8f320221bd612dd5552426_b.png" data-rawwidth="1083" data-rawheight="206" class="origin_image zh-lightbox-thumb" width="1083" data-original="https://pic3.zhimg.com/fa46001dee8f320221bd612dd5552426_r.png"><img src="https://pic1.zhimg.com/96c062c8a17162a7e229d9cd99ec7994_b.png" data-rawwidth="1057" data-rawheight="219" class="origin_image zh-lightbox-thumb" width="1057" data-original="https://pic1.zhimg.com/96c062c8a17162a7e229d9cd99ec7994_r.png">第一张图是锤子T1,第二张是一加2(氧系统)。
第一张图是锤子T1,第二张是一加2(氧系统)。
这种实现有3个问题:
一是只能只用Unicode范围内的表情(其实就是字体文字,只是系统渲染出来看着像表情),当然不一定限定于Emoji范围(比如Unicode 0x2708是个灰机✈);
二是不同系统显示的表情不一样;
三是貌似4.0系统以下不支持。
那我要显示其他表情该怎么办。那就只有自定义通知栏布局了。
看到那个搜狗市场的更新图标了么?布局大致如右侧。也就是 @hi大头鬼hi 同学所说的icon。
那如果真的要图文混排怎么办,那就整个通知栏一个ImageView,然后把文字、图片绘制到一个Bitmap上,然后再设置进去。理论可行。
<img src="https://pic1.zhimg.com/bdf6d67e2f7dadcd1ea966888a125fa4_b.png" data-rawwidth="1033" data-rawheight="680" class="origin_image zh-lightbox-thumb" width="1033" data-original="https://pic1.zhimg.com/bdf6d67e2f7dadcd1ea966888a125fa4_r.png">
最后,上淘宝通知栏显示表情的测试代码。
Emoji Unicode编码可参考附录。
String originalStr = "emoji-" + newString(0x1f602) +newString(0x1f684)+"--over";
Notifier.getInstance().notify(originalStr,originalStr,"tickerText2",Notifier.TYPE_COMMON,false); public static final String newString(int codePoint) {
return new String(Character.toChars(codePoint));
}
作者:RxRead
链接:https://www.zhihu.com/question/34870984/answer/60229859
来源:知乎
著作权归作者所有,转载请联系作者获得授权。 /**
* Notification
*/
public class Notifier { private static Notifier instance = null; private NotificationManager notificationManager; private static Object INSTANCE_LOCK = new Object(); public static final int TYPE_COMMON = ; private static final String TAG = "Notifier"; Intent mLauncherIntent = null;
Notification notification = null; int count = ; public static Notifier getInstance() {
if (instance == null)
synchronized (INSTANCE_LOCK) {
if (instance == null) {
instance = new Notifier();
}
}
return instance;
} private Notifier() {
this.notificationManager = (NotificationManager) ZanPhoneRecorderApplication.getInstance().getSystemService(Context.NOTIFICATION_SERVICE);
} /**
* 清除所有通知
* */
public void cleanAll() {
if (notificationManager != null) {
notificationManager.cancelAll();
}
} public void cancelByType(int type) {
if (notificationManager != null) {
notificationManager.cancel(type);
}
} /**
*/
public void notify(CharSequence title, CharSequence message, String tickerText, int type, boolean canClear) {
try {
Context context = ZanPhoneRecorderApplication.getInstance();
Notification notification = new Notification();
notification.icon = R.mipmap.ic_launcher;
notification.defaults = Notification.DEFAULT_LIGHTS;
// notification.defaults |= Notification.DEFAULT_SOUND;
// notification.defaults |= Notification.DEFAULT_VIBRATE;
if (canClear)
notification.flags |= Notification.FLAG_AUTO_CANCEL;
else
notification.flags |= Notification.FLAG_NO_CLEAR; if (android.os.Build.VERSION.SDK_INT >= ) {// Android 4.1之后才有
notification.priority = Notification.PRIORITY_MAX;
}
notification.tickerText = tickerText; notification.when = System.currentTimeMillis();
Intent intent = new Intent();
PendingIntent contentIntent = null;
switch (type) {
case TYPE_COMMON:
intent.setClass(context, HomeActivity.class);
contentIntent = PendingIntent.getActivity(context, TYPE_COMMON, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, title, message, contentIntent);
break;
}
if (contentIntent != null) {
notification.contentIntent = contentIntent;
notificationManager.notify(type, notification);
}
} catch (Exception e) {
e.printStackTrace();
}
} }

Android Notification如何显示表情?的更多相关文章

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

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

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

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

  3. 3、android notification 详细用法

    在 android 系统中,在应用程序可能会遇到几种情况需要通知用户,有的需要用户回应,有的则不需要,例如: * 当保存文件等事件完成,应该会出现一个小的消息,以确认保存成功. * 如果应用程序在后台 ...

  4. android Notification定义与应用

    首先要明白一个概念: Intent 与 PendingIntent 的区别: Intent:是意图,即告诉系统我要干什么,然后做Intent应该做的事,而intent是消息的内容 PendingInt ...

  5. Android NOtification 使用(震动 闪屏 铃声)

    一. Notification 简介 在 android 系统中,在应用程序可能会遇到几种情况需要通知用户,有的需要用户回应,有的则不需要,例如: * 当保存文件等事件完成,应该会出现一个小的消息,以 ...

  6. Android Notification通知详细解释

    Android Notification通知具体解释  Notification: (一).简单介绍:         显示在手机状态栏的通知. Notification所代表的是一种具有全局效果的通 ...

  7. Android 编辑框插入表情图片

    首先,把整理好的表情图片以及布局用到的一些图片导入到项目的res/drawable目录中. 然后,编辑res/layout目录下布局.xml文件,这里我把oschina客户端的布局代码贴上来,供大家参 ...

  8. Android Notification通知简介

    Android Notification通知简介 根据activity的生命周期,在activity不显示时,会执行onStop函数(比如按下home键),所以你在onStop函数(按退出键除外)里面 ...

  9. Android Notification状态栏通知

    没有添加额外的震动及声音效果,这里直接实现了通知的功能,看效果吧: MainActivity.java package com.example.notification; import android ...

随机推荐

  1. NOIP2016 天天爱跑步(线段树/桶)

    题目描述 小c同学认为跑步非常有趣,于是决定制作一款叫做<天天爱跑步>的游戏.天天爱跑步是一个养成类游戏,需要 玩家每天按时上线,完成打卡任务. 这个游戏的地图可以看作一一棵包含 N个结点 ...

  2. 趣闻|Python之禅(The Zen of Python)

    在Python解释器中输入“import this”会发生什么?如果你不知道这个彩蛋,推荐继续阅读这篇文章. 2001年秋,Foretec(一家会议组织公司)正在准备召开第十届Internationa ...

  3. [D3JS] Add more map layer and color

    import React, {Component} from 'react'; import * as d3 from 'd3'; import 'd3-geo'; import * as topoj ...

  4. win7打不开chm格式文件

           近期在开发的过程中,发现重装的系统Wind7 打不开java帮助文档.搜索了半天才找到. 在这里分享一下. 一.假设不能打开,可这样恢复文件关联: 1.開始执行,输入:regsvr32 ...

  5. ORA-01665 control file is not a standby control file

    ORA-01665错误处理 问题描述: 在备库启动至mount状态时,报如下错误: ORA-01665: control file is not a standby control file 解决办法 ...

  6. 三期_day03_环境搭建和客户页面_I

    以下交代一下使用的框架 前端: EasyUI+Jquery+Ajax 后台: Spring+Structs2+mybatis 数据库: Oracle 使用工具: MyEclipse12+Maven 操 ...

  7. python3 随机生成6位数的验证码

    python3 随机生成6位数的验证码 要求是数字:0~9 及大小写字母. #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung ...

  8. 为什么通过空指针(NULL)能够正确调用类的部分成员函数

    #include <iostream> using namespace std; class B { public: void foo() { cout << "B ...

  9. Qt开发程序在Windows 10应用须要管理员执行的解决思路

    Qt开发程序在Windows 10应用须要管理员执行的解决思路 过了非常长的时间没有公布博客了.可是我依旧努力地开发Qt程序.眼下呢.我发现开发Qt程序在Windows 10上有一个怪现象--有些程序 ...

  10. swift 数据存储

    1.plist 存储 1.利用沙盒根目录拼接“Documents”字符串 //存储 func saveArray() { // 1.获得沙盒根路径,不管是真机还是模拟机,用它是最合适不过了 let h ...