Google为了统一风格,对消息列表的图标做了统一处理,设置消息icon的时候不能随便用一张带有色彩的图片,只能使用白色和透明两个颜色,具体设置代码位置在frameworks/base/core/java/android/app/Notification.java类中的processSmallIconColor()中
private void processSmallIconColor(Icon smallIcon, RemoteViews contentView,
boolean ambient) {
boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon);
int color = ambient ? resolveAmbientColor() : getPrimaryHighlightColor();
if (colorable) {
contentView.setDrawableParameters(R.id.icon, false, -1, color,
PorterDuff.Mode.SRC_ATOP, -1);
}
contentView.setInt(R.id.notification_header, "setOriginalIconColor",
colorable ? color : NotificationHeaderView.NO_COLOR);
}
在processSmallIconColor方法中,其中的colorable变量用来判断是否对图标来进行着色,其中的isLegacy方法用来判断SDK版本,如果版本小于LOLLIPOP为true,另外一个方法用来判断图标是否是grayscale图标,根据判断条件可知:
1.首先判断APK的target version是Android L之后,如果是则直接会主动上色
2.如果在Android L之前则判断图片是否为Grayscale(灰度图),如果为灰度图的话也会有一个上色的操作
colorable决定系统会不会主动上色,这块代码主要影响NotificationHeaderView的图标显示
还有一个地方frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconAreaController.java
private void applyNotificationIconsTint() {
for (int i = 0; i < mNotificationIcons.getChildCount(); i++) {
final StatusBarIconView iv = (StatusBarIconView) mNotificationIcons.getChildAt(i);
if (iv.getWidth() != 0) {
updateTintForIcon(iv);
} else {
iv.executeOnLayout(() -> updateTintForIcon(iv));
}
}
}
这块代码主要影响状态栏的图标,知道了这两处的位置就可以Android 进行客制化设置