最爱半场开香槟 2024-04-10 09:54 采纳率: 0%
浏览 41
已结题

Android13 systemui悬浮通知加载流程

Android13中,SystemUI中悬浮通知通过哪些方法最终显示在屏幕顶部;现在我自己在status_bar_expanded中加入了个布局,大致如下,现在问题是每次悬浮通知出现时,会将我的添加的背景布局一同展现,我需要在悬浮通知加载完成后,将自己的背景布局设为不可见。

<com.android.systemui.statusbar.phone.NotificationPanelView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:systemui="http://schemas.android.com/apk/res-auto"
    android:id="@+id/notification_panel"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">

    <ImageView
        android:id="@+id/blur_view"
        android:layout_width="match_parent"
        android:scaleType="centerCrop"
        android:foreground="#3d000000"
        android:layout_height="match_parent"/>

    <View
        android:id="@+id/alpha_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:foreground="#50000000"/>

........
........

</com.android.systemui.statusbar.phone.NotificationPanelView>
  • 写回答

10条回答 默认 最新

  • 专家-赤兔[在线] 全栈领域优质创作者 2024-04-10 09:54
    关注

    引自免费微信小程序:皆我百晓生

    在Android 13中,SystemUI中的悬浮通知(heads-up notifications)的加载和展示过程涉及多个组件协同工作。以下是一个简化的概述:

    1. Notification消息创建:首先,应用程序通过NotificationCompat.Builder构建并发布一个通知,该通知具有NotificationCompat.Builder.setPriority()设置为PRIORITY_HIGH_IMPORTANCE或满足heads-up条件的通知优先级。

    2. 系统通知管理:系统收到高优先级通知后,将其传递给SystemUI进程中的NotificationManagerService(NMS),进一步处理。

    3. Heads-up Notification呈现:在SystemUI中,HeadsUpNotificationController负责监测到新到达的符合条件的通知,并调用相应的逻辑来显示heads-up通知视图。

    4. 布局渲染与动画:当heads-up通知需要显示时,它会在Status Bar区域下方以一种浮动窗口的形式展现。在您的代码片段中,NotificationPanelView是包含所有通知元素的父容器,而heads-up通知会被动态插入到其子视图层级中。

    5. 控制背景布局可见性:您提到的问题是在heads-up通知出现时,希望隐藏自己添加的背景布局(如blur_viewalpha_view)。这可以通过监听heads-up通知的状态变化实现,例如:

      • 监听通知栏展开事件:可以注册一个监听器来监听状态栏展开或收起的动作,然后在通知栏展开且heads-up通知显示时,将背景布局设为View.GONEView.INVISIBLE
      • 使用系统提供的接口:如果SystemUI提供了相关回调或接口来处理heads-up通知显示和隐藏,您可以重写或监听这些接口来控制背景布局的可见性。

    示例性的伪代码可能如下:

    // 假设有获取HeadsUpManager实例的方法
     HeadsUpManager headsUpManager = getHeadsUpManager();
    
    // 注册监听器
    headsUpManager.addOnHeadsUpChangedListener(new OnHeadsUpChangedListener() {
        @Override
        public void onHeadsUpPinned(NotificationEntry entry) {
            findViewById(R.id.blur_view).setVisibility(View.INVISIBLE);
            findViewById(R.id.alpha_view).setVisibility(View.INVISIBLE);
        }
    
        @Override
        public void onHeadsUpUnpinned(NotificationEntry entry) {
            // 当heads-up通知消失时恢复背景布局的可见性
            findViewById(R.id.blur_view).setVisibility(View.VISIBLE);
            findViewById(R.id.alpha_view).setVisibility(View.VISIBLE);
        }
    });
    

    请注意,由于SystemUI源码不在公共API范围内,上述代码仅为示意,实际操作可能需要基于反射或者其他非公开方式接入系统内部接口。若要更准确地解决问题,您可能需要查阅AOSP源码或者找到对应版本SystemUI暴露出来的可扩展点。

    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月10日
  • 创建了问题 4月10日

悬赏问题

  • ¥15 Collection contains no element matching the predicate
  • ¥20 冻品电商平台的搜索是怎么实现的
  • ¥15 如何搞一个可以控制、显示马达频率
  • ¥15 WPF动态创建页面内容
  • ¥15 如何对TBSS的结果进行统计学的分析已完成置换检验,如何在最终的TBSS输出结果提取除具体值及如何做进一步相关性分析
  • ¥15 SQL数据库操作问题
  • ¥100 关于lm339比较电路出现的问题
  • ¥15 Matlab安装yalmip和cplex功能安装失败
  • ¥15 加装宝马安卓中控改变开机画面
  • ¥15 STK安装问题问问大家,这种情况应该怎么办