Android 9 Notification 创建显示流程 更改通知显示文本颜色
发布日期:2021-06-29 01:27:25 浏览次数:2 分类:技术文章

本文共 3486 字,大约阅读时间需要 11 分钟。

1、在应用中创建Notification 这里是创建并发送一个通知,

Notification notification2 = null;                CharSequence aVeryLongString="hello";                // 如果当前Android的版本相比Android O,一样或者版本更高,就建通知渠道(Notification Channels )                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//判断API //1.0 建渠道 NotificationChannel mChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_LOW); //2.0 把通知渠道通过createNotificationChannel( )方法给- // -状态栏通知的管理类 NotificationManager manager.createNotificationChannel(mChannel); //3.0 Notification这时候可以正常工作了 CharSequence cs="hello"; NotificationCompat.BigTextStyle bs = new NotificationCompat.BigTextStyle().bigText(cs); notification2 = new NotificationCompat.Builder(this, id) .setStyle(bs) .setContentTitle("这是一个内容标题2")//设置通知栏标题 .setContentText("这是一个内容文本2") //设置通知栏显示内容 .setWhen(System.currentTimeMillis())//通知产生的时间。 .setSmallIcon(R.mipmap.ic_launcher)//设置通知小ICON .setLargeIcon(BitmapFactory.decodeResource(getResources() , R.mipmap.ic_launcher))//设置通知大ICON .build(); } manager.notify(1, notification2);

2、systemUI 中显示通知

1.SystemUIFactory 创建NotificationListener,它是一个服务,用于plugin监听和通知的监听
在这里插入图片描述

2.如果有通知会onNotificationPosted 这里,分两类

1) mEntryManager.updateNotification(sbn, rankingMap);更通知
2) mEntryManager.addNotification(sbn, rankingMap);添加通知
3.SystemUI用 Dependency 创建ForegroundServiceControllerImpl对象,这是以个控制器,真正的使用是在
在这里插入图片描述
4.通知的管理以及布局的解析都是在NotificationEntryManager类中。(省略)
ExpandableNotificationRow具体通知的显示
NotificationShelf将通知变化成图标,在快捷面板拉伸时显示。
FooterView 显示“通知管理”和“全部清除”按钮
在这里插入图片描述
NotificationEntryManagerupdateNotification -> updateNotificationInternal() -> inflateViews()->updateNotification()

private void inflateViews(NotificationData.Entry entry, ViewGroup parent) {
PackageManager pmUser = StatusBar.getPackageManagerForUser(mContext, entry.notification.getUser().getIdentifier()); final StatusBarNotification sbn = entry.notification; if (entry.row != null) {
entry.reset(); updateNotification(entry, pmUser, sbn, entry.row); } else {
new RowInflaterTask().inflate(mContext, parent, entry, row -> {
bindRow(entry, pmUser, sbn, row); updateNotification(entry, pmUser, sbn, row); }); } }

接下来会调到这里inflateNotificationViews解析布局。最终会计算出显示的文本颜色。

public void updateNotification(NotificationData.Entry entry) {
mEntry = entry; mStatusBarNotification = entry.notification; mNotificationInflater.inflateNotificationViews(); cacheIsSystemNotification(); }

在这里插入图片描述

最终在frameworks/base/core/res/res/values/colors.xml配置通知文本显示的颜色。 可以在overlay中更改。

@color/primary_text_default_material_light
//大标题显示的颜色 内容
@color/primary_text_default_material_dark
@color/primary_text_default_material_light
// 小文本显示的颜色 时间
0.38
@color/primary_text_default_material_dark
@color/primary_text_default_material_light
#a3202124
```

转载地址:https://blog.csdn.net/yt_42370304/article/details/117784519 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:ubuntu下软件安装卸载与查看
下一篇:Android 9 SystemUI通知栏中“通知条目”的位置更新与NotificationShelf、FooterView重叠

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月25日 03时35分34秒