Android Notification如何显示表情?
打开之后,选中连接的设备,然后点击小手机图标,即可导出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(氧系统)。
这种实现有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如何显示表情?的更多相关文章
- Android Notification 详解(一)——基本操作
Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...
- Android Notification 详解——基本操作
Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...
- 3、android notification 详细用法
在 android 系统中,在应用程序可能会遇到几种情况需要通知用户,有的需要用户回应,有的则不需要,例如: * 当保存文件等事件完成,应该会出现一个小的消息,以确认保存成功. * 如果应用程序在后台 ...
- android Notification定义与应用
首先要明白一个概念: Intent 与 PendingIntent 的区别: Intent:是意图,即告诉系统我要干什么,然后做Intent应该做的事,而intent是消息的内容 PendingInt ...
- Android NOtification 使用(震动 闪屏 铃声)
一. Notification 简介 在 android 系统中,在应用程序可能会遇到几种情况需要通知用户,有的需要用户回应,有的则不需要,例如: * 当保存文件等事件完成,应该会出现一个小的消息,以 ...
- Android Notification通知详细解释
Android Notification通知具体解释 Notification: (一).简单介绍: 显示在手机状态栏的通知. Notification所代表的是一种具有全局效果的通 ...
- Android 编辑框插入表情图片
首先,把整理好的表情图片以及布局用到的一些图片导入到项目的res/drawable目录中. 然后,编辑res/layout目录下布局.xml文件,这里我把oschina客户端的布局代码贴上来,供大家参 ...
- Android Notification通知简介
Android Notification通知简介 根据activity的生命周期,在activity不显示时,会执行onStop函数(比如按下home键),所以你在onStop函数(按退出键除外)里面 ...
- Android Notification状态栏通知
没有添加额外的震动及声音效果,这里直接实现了通知的功能,看效果吧: MainActivity.java package com.example.notification; import android ...
随机推荐
- arukas 的 Endpoint
arukas 的 Endpoint 什么是端点 What is Endpoint arukas.io 的实例几乎每周都自动重新启动,当实例重新启动时,其端口会更改.IP地址和端口的平均寿命是一周,有时 ...
- event事件对象 兼容写法:var oEvent=ev||event;和取消事件冒泡
要在整个页面添加事件要使用document,例如要捕抓鼠标位置 document.onclink=function(ev) //FireFox Chrome默认都是有一个值传进来的 { var oE ...
- js数组遍历和对象遍历小结
数组的遍历 for循环 for(var j = 0,len = arr.length; j < len; j++){ console.log(arr[j]); } forEach,性能比for还 ...
- C++ 多线程阻塞 (多线程同步)(MsgWaitForMultipleObjects)(连着消息一起控制,牛)
在主线程定要禁止使用waitforsingleobject(),原因是会阻塞主线程的消息循环,所以必须使用另一种 MsgWaitForMultipleObjects,即可以让消息通过,下面就是一个基于 ...
- web.config访问走代理的配置
<system.net> <defaultProxy> <proxy bypassonlocal="False" usesystemd ...
- 在react底下安装环境
1.在react底下安装环境 Image.png Image.png 2.新建一个文件夹 Image.png 3.配置入口文件redux:staticRoot+'/redux/app' Image.p ...
- FTP中的授权规则
在授权规则中,你可以管理自己的FTP站点以怎样的方式进行访问,比如每个进入站点的人都需要输入用户名密码.正则可以在授权规则中删除默认的配置“允许匿名用户读取”的规则. 也可以在此处,对不同的组或用户进 ...
- (转)nginx的root和alias指令的区别
转自 http://www.cnblogs.com/tintin1926/archive/2012/07/11/2586813.html nginx配置下有两个指定目录的执行,root和alias ...
- 10.3、android输入系统_必备Linux编程知识_任意进程双向通信(scoketpair+binder)
3. 任意进程间通信(socketpair_binder) 进程每执行一次open打开文件,都会在内核中有一个file结构体表示它: 对每一个进程在内核中都会有一个task_struct表示进程,这个 ...
- 动态布局Cell的高度
1 自定义Cell, 在Cell的构造方法里面添加好所有的子控件 2 3 2 在HeightForRowAtIndexPath方法中返回每一行Cell对应的高度 4 5 3 在Cell的layoutS ...