Android10修改图标/字体大小

先上结论
修改packages/apps/Launcher3/res/xml/device_profiles.xml里

launcher:iconImageSize="24"
launcher:iconTextSize="24"

这样的地方即可

追源码过程

网上大部分都说改dimens.xml里的iconsize,改了编译之后发现不管用,于是自己找
现在packages/apps/找到Launcher3
这个相关内容是控制桌面显示的
进入
src/com/android/launcher3
找icon相关,发现一个IconProvider.java
打开之后虽然有一个

public Drawable getIcon(LauncherActivityInfo info, int iconDpi, boolean flattenDrawable) 

看名字是返回Icon的,但是只定义了icon的密度(dpi)
于是再找,有一个icons文件夹,打开发现有四个文件

ComponentWithLabel.java  
IconCache.java  
LauncherActivtiyCachingLogic.java 
LauncherIcons.java

看名字定义icons的有一个LauncherIcons.java
搜索size关键字,发现了方法有两处有iconBitmapSize,
一处是构造函数,另一处是在其obtain方法里,源代码如下
packages/apps/Launcher3/src/com/android/launcher3/icons/LauncherIcons.java

LauncherIcons.java

 private LauncherIcons(Context context, int fillResIconDpi, int iconBitmapSize, int poolId,
            boolean shapeDetection) {
   /*第一处*/     super(context, fillResIconDpi,iconBitmapSize, shapeDetection);
        mPoolId = poolId;
    }



/**
     * Return a new Message instance from the global pool. Allows us to
     * avoid allocating new objects in many cases.
     */
    public static LauncherIcons obtain(Context context, boolean shapeDetection) {
        int poolId;
        synchronized (sPoolSync) {
            if (sPool != null) {
                LauncherIcons m = sPool;
                sPool = m.next;
                m.next = null;
                return m;
            }
            poolId = sPoolId;
        }

        InvariantDeviceProfile idp = LauncherAppState.getIDP(context);
   /*第二处*/     return new LauncherIcons(context, idp.fillResIconDpi, idp.iconBitmapSize, poolId,
                shapeDetection);
    }

我们只需关注给iconBitmapSize赋值的地方

而其中Obtain方法里的iconBitmapSize是直接使用已经被定义过的idp.iconBitmapSize

所以我们只需关注其构造函数里的iconBitmapSize,即第一处地方
直接调用父类的构造方法

public class LauncherIcons extends BaseIconFactory implements AutoCloseable {

查找BaseIconFacory,
/packages/apps/Launcher3/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java
查找iconBitmapSize

protected final int mIconBitmapSize;

查找mIconBitmapSize赋值的地方,只有在其构造函数的地方赋值

BaseIconFactory.java

protected BaseIconFactory(Context context, int fillResIconDpi, int iconBitmapSize,
            boolean shapeDetection) {
       .....
        mIconBitmapSize = iconBitmapSize;
        .....
    }

所以到目前,知道了要为设置icon的size,只有在创建BaseIconFactory或者其子类LauncherIcons的时候进行修改
于是在/packages/apps/Launcher3下
进行查询命令

 grep -nir "BaseIconFactory"
 grep -nir "LauncherIcons"

两条命令分别查询,发现new对象的地方只有一个

src/com/android/launcher3/graphics/LauncherPreviewRenderer.java:101:              
  new BaseIconFactory(context, mIdp.fillResIconDpi, mIdp.iconBitmapSize) { };
Binary file .git/index matches

打开LauncherPreviewRenderer.java 到101行

LauncherPreviewRenderer.java

 private final InvariantDeviceProfile mIdp;
  ...
 BaseIconFactory iconFactory =
                new BaseIconFactory(context, mIdp.fillResIconDpi, mIdp.iconBitmapSize) { };

发现图标的大小来自mIdp.iconBitmapSize
而mIdp是InvariantDeviceProfile 类;
这时就该去找InvariantDeviceProfile.java
Launcher3/src/com/android/launcher3/InvariantDeviceProfile.java

InvariantDeviceProfile.java

 private static final class DisplayOption {
        private final GridOption grid;
        ...
        private float iconSize;
         ...
            TypedArray a = context.obtainStyledAttributes(
                    attrs, R.styleable.ProfileDisplayOption);
                    ...
            iconSize = a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
            iconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
        }

过滤掉无用信息后,发现是通过R.styleable.ProfileDisplayOption_iconImageSize来赋值的
用的是styleable
找到res/values/attrs.xml这个文件发现其定义为

       <attr name="iconImageSize" format="float" />
       <attr name="iconTextSize" format="float" />

在res下查找其赋值的地方

grep -nir "iconTextSize"
grep -nir "iconImageSize"

找到

xml/device_profiles.xml:34:            launcher:iconTextSize="13.0"
xml/device_profiles.xml:42:            launcher:iconTextSize="13.0"
xml/device_profiles.xml:61:            launcher:iconTextSize="13.0"
xml/device_profiles.xml:69:            launcher:iconTextSize="13.0"
xml/device_profiles.xml:77:            launcher:iconTextSize="13.0"
xml/device_profiles.xml:85:            launcher:iconTextSize="13.0"
xml/device_profiles.xml:93:            launcher:iconTextSize="13.0"
xml/device_profiles.xml:112:            launcher:iconTextSize="14.4"
xml/device_profiles.xml:120:            launcher:iconTextSize="13.0"

xml/device_profiles.xml:33:            launcher:iconImageSize="24"
xml/device_profiles.xml:41:            launcher:iconImageSize="24"
xml/device_profiles.xml:60:            launcher:iconImageSize="24"
xml/device_profiles.xml:68:            launcher:iconImageSize="24"
xml/device_profiles.xml:76:            launcher:iconImageSize="24"
xml/device_profiles.xml:84:            launcher:iconImageSize="24"
xml/device_profiles.xml:92:            launcher:iconImageSize="24"
xml/device_profiles.xml:111:            launcher:iconImageSize="24"
xml/device_profiles.xml:119:            launcher:iconImageSize="24"

则修改Launcher3/res/xml/device_profiles.xml
里定义图标和字体大小的地方就可以了.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值