android n 状态栏分析,Android N状态栏图标白底问题

问题背景

最近定制项目中,客户反馈自己的apk在收到通知时,状态栏图标全是白色底方框图片,不能正常显示用户代码里面加载的图片资源。

问题原因

这个是Android N对通知栏图标处理设计如此,处理逻辑如下:

首先判断APK的target version是Android L之后,如果是则直接会主动上色

如果在Android L之前则判断图片是否为Grayscale(灰度图),如果为灰度图的话也会有一个上色的操作.

涉及的代码有两块:

frameworks/base/core/java/android/app/Notification.java

/**

* Apply any necessariy colors to the small icon

*/

private void processSmallIconColor(Icon smallIcon, RemoteViews contentView) {

boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon);

if (colorable) {

contentView.setDrawableParameters(R.id.icon, false, -1, resolveContrastColor(),

PorterDuff.Mode.SRC_ATOP, -1);

}

contentView.setInt(R.id.notification_header, "setOriginalIconColor",

colorable ? resolveContrastColor() : NotificationHeaderView.NO_COLOR);

}

colorable决定系统会不会主动上色,这块代码主要影响NotificationHeaderView的图标显示

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconAreaController.java

/**

* Applies {@link #mIconTint} to the notification icons.

*/

private void applyNotificationIconsTint() {

for (int i = 0; i < mNotificationIcons.getChildCount(); i++) {

StatusBarIconView v = (StatusBarIconView) mNotificationIcons.getChildAt(i);

boolean isPreL = Boolean.TRUE.equals(v.getTag(R.id.icon_is_pre_L));

boolean colorize = !isPreL || NotificationUtils.isGrayscale(v, mNotificationColorUtil);

if (false) {

v.setImageTintList(ColorStateList.valueOf(

StatusBarIconController.getTint(mTintArea, v, mIconTint)));

}

}

}

这块代码主要影响状态栏的图标,知道了这两处的位置就可以Android N进行客制化设置,比如小米会提取应用的Launcher Icon来做填充

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值