Android Launcher3修改应用图标,隐藏应用图标

Launcher运行时,会执行LauncherModel的loadAllApps方法,加载所有应用的详细信息。这时候,如果你想过

滤掉你不想显示的应用,你可以修改源码,把应用过滤掉。

我这里的示列是Launcher第一次加载时,会把Android的键盘应用添加到主页面。所以我需要把该应用隐藏,不

显示在Launcher桌面。这里贴LoadAllApps的部分代码。

// Create the ApplicationInfos
for (int i = 0; i < apps.size(); i++) {
    LauncherActivityInfoCompat app = apps.get(i);
    // This builds the icon bitmaps.
    AppInfo appInfo = new AppInfo(mContext, app, user, mIconCache, mLabelCache);
//  Log.e(TAG, "packagename: "+appInfo.componentName.getPackageName());
    //隐藏AndroidAOSP加载到桌面
    if (!appInfo.componentName.getPackageName().equals("com.android.inputmethod.latin")){
        mBgAllAppsList.add(appInfo);
//  Log.e(TAG, "packagename222: "+appInfo.componentName.getPackageName());
    }else{
        //过滤掉该APP,不显示在Launcher界面中
    }
}

通过追踪代码,你会发现,控制APP应用图标的代码在IconCache的cacheLocked方法中。当然,你也可以在其他地方修改。这个没有限制。判断应用的包名和你应用的需要修改的一致,这时候就可以修改应用的包名了

 

/**
 * Retrieves the entry from the cache. If the entry is not present, it creates a new entry.
 * This method is not thread safe, it must be called from a synchronized method.
 */
private CacheEntry cacheLocked(ComponentName componentName, LauncherActivityInfoCompat info,
        HashMap<Object, CharSequence> labelCache, UserHandleCompat user, boolean usePackageIcon) {
    CacheKey cacheKey = new CacheKey(componentName, user);
    CacheEntry entry = mCache.get(cacheKey);
    if (entry == null) {
        entry = new CacheEntry();
        mCache.put(cacheKey, entry);

        if (info != null) {
            ComponentName labelKey = info.getComponentName();
            if (labelCache != null && labelCache.containsKey(labelKey)) {
                entry.title = labelCache.get(labelKey).toString();
            } else {
                entry.title = info.getLabel().toString();
                if (labelCache != null) {
                    labelCache.put(labelKey, entry.title);
                }
            }

            entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
            entry.icon = Utilities.createIconBitmap(
                    info.getBadgedIcon(mIconDpi), mContext);

            Log.d(TAG, "PackageName: "+componentName.getPackageName());
            
            
            /**
             * 这里修改图标
             */
            //设置
            if (componentName.getPackageName().equals("com.android.settings")) {

                Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(),
                        R.mipmap.system_setting);
                entry.icon = bitmap;
            }

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值