一、我们可以在Launcher3中找到默认图标形状的配置,可以看到默认配置的几个图标形状,这个地方并不能修改默认图标的形状,因为icon_shape_system_default对应的值为空。
- M50,0L100,0 100,100 0,100 0,0z
- M50,0 C10,0 0,10 0,50 0,90 10,100 50,100 90,100 100,90 100,50 100,10 90,0 50,0 Z
- M50 0A50 50,0,1,1,50 100A50 50,0,1,1,50 0
- M50,0A50,50,0,0 1 100,50 L100,85 A15,15,0,0 1 85,100 L50,100 A50,50,0,0 1 50,0z
- @string/icon_shape_system_default
- @string/icon_shape_square
- @string/icon_shape_squircle
- @string/icon_shape_circle
- @string/icon_shape_teardrop
二、从绘制Adaptive icon的地方入手,找到AdaptiveIconDrawable.java,路径如下:
./base/graphics/java/android/graphics/drawable/AdaptiveIconDrawable.java
查看其构造方法:
/**
* The one constructor to rule them all. This is called by all public
* constructors to set the state and initialize local properties.
*/
AdaptiveIconDrawable(@Nullable LayerState state, @Nullable Resources res) {
mLayerState = createConstantState(state, res);
if (sMask == null) {
sMask = PathParser.createPathFromPathData(
Resources.getSystem().getString(R.string.config_icon_mask));
}
mMask = PathParser.createPathFromPathData(
Resources.getSystem().getString(R.string.config_icon_mask));
mMaskMatrix = new Matrix();
mCanvas = new Canvas();
mTransparentRegion = new Region();
}
可以看到用到了config_icon_mask 字段,该字段是在framework中配置的,大概意思就是通过config_icon_mask来获取对应的icon shape.
三、查看android/frameworks/base/core/res/res/values/config.xml 中的config_icon_mask值
"M50,0L92,0C96.42,0 100,4.58 100 8L100,92C100, 96.42 96.42 100 92 100L8 100C4.58, 100 0 96.42 0 92L0 8 C 0 4.42 4.42 0 8 0L50 0Z"
可以知道该值就是默认的adaptive icon的形状,我们把其值改为我们想要的值即可,值可以参考,launcher3中的配置,比如我们想改为正方形,就改为M50,0L100,0 100,100 0,100 0,0z 即可。
支持,android系统里面所有使用了adaptive icon 特性功能的,都会遵循这个规则。