Android 9 Notification 创建显示流程 更改通知显示文本颜色

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 name="notification_primary_text_color_light">@color/primary_text_default_material_light</color> //大标题显示的颜色 内容
    <color name="notification_primary_text_color_dark">@color/primary_text_default_material_dark</color>
    <color name="notification_secondary_text_color_light">@color/primary_text_default_material_light</color>// 小文本显示的颜色 时间
    <item name="notification_secondary_text_disabled_alpha" format="float" type="dimen">0.38</item>
    <color name="notification_secondary_text_color_dark">@color/primary_text_default_material_dark</color>
    <color name="notification_default_color_dark">@color/primary_text_default_material_light</color>
    <color name="notification_default_color_light">#a3202124</color>
    ```

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值