android8.1状态栏图标,Android 8.1 去掉 Launcher3 默认给 icon 增加的白边
前言
如果你還不知道 icon 白邊是什么的話,請移步這篇 Android應用圖標微技巧,8.0系統中應用圖標的適配 看一下
為了避免 app 圖標適配的工作,手里有源碼就是爽,我們可以修改源碼把這個白邊去掉,如果你沒有源碼就老老實實按照
上面博客的方法進行適配吧。
修改前效果
修改后效果
思路
從上文的博客介紹可以得知只要 app 的 AndroidManifest.xml 中 targetSdkVersion 的值 >= 26,如果你沒進行適配,Launcher3
就會給你的 app 圖標增加一個默認的白色遮罩。 targetSdkVersion 的值 < 26, 則使用原來的圖標。
好了,那么在 Launcher3 中必定有判斷 targetSdkVersion 的代碼,26 對應的變量為 Build.VERSION_CODES.O
通過全局搜索會有很多相關的,過濾我們需要的
packages\apps\Launcher3\src\com\android\launcher3\graphics\LauncherIcons.java
修改方法如下
可以看到 進行了雙重判斷,當前編譯系統的 SDK 版本是否是 23 和 iconapp 的 targetSdk 版本是否大于 23
將 if 部分直接注釋,默認走 else 部分,不添加白邊
/**
* Returns a bitmap suitable for the all apps view. The icon is badged for {@param user}.
* The bitmap is also visually normalized with other icons.
*/
public static Bitmap createBadgedIconBitmap(
Drawable icon, UserHandle user, Context context, int iconAppTargetSdk){
IconNormalizer normalizer;
float scale = 1f;
if (!FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION) {
normalizer = IconNormalizer.getInstance(context);
//annotation for don't add white mask outshape when targetsdk >= 26
/*if (Utilities.ATLEAST_OREO && iconAppTargetSdk >= Build.VERSION_CODES.O) {
boolean[] outShape = new boolean[1];
AdaptiveIconDrawable dr = (AdaptiveIconDrawable)
context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate();
dr.setBounds(0, 0, 1, 1);
scale = normalizer.getScale(icon, null, dr.getIconMask(), outShape);
if (FeatureFlags.LEGACY_ICON_TREATMENT &&
!outShape[0]){
Drawable wrappedIcon = wrapToAdaptiveIconDrawable(context, icon, scale);
if (wrappedIcon != icon) {
icon = wrappedIcon;
scale = normalizer.getScale(icon, null, null, null);
}
}
} else {
scale = normalizer.getScale(icon, null, null, null);
}*/
scale = normalizer.getScale(icon, null, null, null);
}
Bitmap bitmap = createIconBitmap(icon, context, scale);
if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.ATLEAST_OREO &&
icon instanceof AdaptiveIconDrawable) {
bitmap = ShadowGenerator.getInstance(context).recreateIcon(bitmap);
}
return badgeIconForUser(bitmap, user, context);
}
復制代碼
總結
以上是生活随笔為你收集整理的android8.1状态栏图标,Android 8.1 去掉 Launcher3 默认给 icon 增加的白边的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 辛巴被旗下主播讨薪 快手带货一哥风波不
- 下一篇: 利率上浮5%怎么算