问题及现象
从android L版本开始,为了统一图标样式,会将通知栏、状态栏等显示图标处统一为白底或黑底,以促使开发人员规范图标设计。
从现象看,状态栏会显示一个白底的方框;下拉通知栏展开时的图标为白底方框加圆框,不展开时为黑底方框。
解决方案
通过trace log定位填色代码,以下两处有助于定位代码
R.id.icon_is_pre_L
targetSdkVersion < Build.VERSION_CODES.LOLLIPOP
可见通过修改targetSdkVersion小于Build.VERSION_CODES.LOLLIPOP(21)即可,但适配新平台,特别是高版本android 11 13 (有跃升)很困难。
这里不得不吐嘈一下android开发环境,在应用开发的黄金时期,大量APP如雨后纯笋,为无数商家获得大量回报,而当这些APP趋于稳定后,一些公司为了成本,裁掉了一大批APP开发人员,在低维护成本的情况下,尝到了甜头。
但是android作为科技领域的开拓者,前行的步伐不可能停止,越来越新的技术使得APP过于老老老,无法及时更新换代,就会导致一系列问题,甚至是业务问题。
博主是一名framework开发选手,对此深恶痛绝,客户来一句“APP不能改作为理由”,犹如圣旨一般,系统就必须适配,把android原生优美的框架代码改得一塌糊涂,涉及安全性的代码更惨不忍睹。
言归正传,上代码(以MTK平台代码为例):
framework层添加配置统一控制功能
Index: frameworks/base/core/res/res/values/config.xml
===================================================================
--- frameworks/base/core/res/res/values/config.xml (版本 349)
+++ frameworks/base/core/res/res/values/config.xml (版本 353)
@@ -5832,4 +5832,7 @@<string-array name="config_serviceStateLocationAllowedPackages"><item>"com.android.phone"</item></string-array>
+
+ <!-- @ + Compatible with non-standard image resources -->
+ <bool name="config_enable_icon_colorized">false</bool></resources>
Index: frameworks/base/core/res/res/values/symbols.xml
===================================================================
--- frameworks/base/core/res/res/values/symbols.xml (版本 349)
+++ frameworks/base/core/res/res/values/symbols.xml (版本 353)
@@ -4809,4 +4809,6 @@<!-- @ + for watermark -->
+
+ <java-symbol type="bool" name="config_enable_icon_colorized" /></resources>
状态栏
Index: vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconAreaController.java
===================================================================
--- vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconAreaController.java (版本 349)
+++ vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconAreaController.java (版本 353)
@@ -483,8 +483,13 @@private void updateTintForIcon(StatusBarIconView v, int tint) {boolean isPreL = Boolean.TRUE.equals(v.getTag(R.id.icon_is_pre_L));
+ // @ modify {
+ boolean enableIconColorized = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_enable_icon_colorized);int color = StatusBarIconView.NO_COLOR;
- boolean colorize = !isPreL || NotificationUtils.isGrayscale(v, mContrastColorUtil);
+ boolean colorize = enableIconColorized ?
+ (!isPreL || NotificationUtils.isGrayscale(v, mContrastColorUtil)) : false;
+ // @ modify }if (colorize) {color = DarkIconDispatcher.getTint(mTintAreas, v, tint);}
下拉通知栏
展开
Index: frameworks/base/core/java/android/app/Notification.java
===================================================================
--- frameworks/base/core/java/android/app/Notification.java (版本 349)
+++ frameworks/base/core/java/android/app/Notification.java (版本 353)
@@ -6437,7 +6437,12 @@*/private void processSmallIconColor(Icon smallIcon, RemoteViews contentView,StandardTemplateParams p) {
- boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon);
+ // @ modify {
+ boolean enableIconColorized = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_enable_icon_colorized);
+ boolean colorable = enableIconColorized ?
+ (!isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon)) : false;
+ // @ modify }int color = getSmallIconColor(p);contentView.setInt(R.id.icon, "setBackgroundColor",getBackgroundColor(p));
不展开
Index: vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconContainer.java
===================================================================
--- vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconContainer.java (版本 349)
+++ vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconContainer.java (版本 353)
@@ -187,8 +187,12 @@mStaticDotDiameter = 2 * mStaticDotRadius;final Context themedContext = new ContextThemeWrapper(getContext(),com.android.internal.R.style.Theme_DeviceDefault_DayNight);
- mThemedTextColorPrimary = Utils.getColorAttr(themedContext,
- com.android.internal.R.attr.textColorPrimary).getDefaultColor();
+ // @ modify {
+ boolean enableIconColorized = getResources().getBoolean(
+ com.android.internal.R.bool.config_enable_icon_colorized);
+ mThemedTextColorPrimary = enableIconColorized ? Utils.getColorAttr(themedContext,
+ com.android.internal.R.attr.textColorPrimary).getDefaultColor() : StatusBarIconView.NO_COLOR;
+ // @ modify }}@Override