Android第三方无源码应用图标icon定制、修改、替换与添加背景

您所在的位置:网站首页 app修改图标和名字下载安装 Android第三方无源码应用图标icon定制、修改、替换与添加背景

Android第三方无源码应用图标icon定制、修改、替换与添加背景

2024-07-13 17:32| 来源: 网络整理| 查看: 265

为适配的各种UI,客户经常会对要求应用的图标进行替换、定制或修改。修改的方式有很多,效果也不尽相同,本文章将会把所有的修改方式与君解析。

目录

替换应用图标

一、Launcher层面修改

通过BubbleTextView.java修改

通过IconCache.java修改

二、系统层面修改

Android11之前的修改方式

Android11之后的修改方式

添加应用图标背景

Android11之前

Android11之后

移除图标白边,图标铺满

Android11之前

Android11之后

替换应用图标 一、Launcher层面修改

缺点:仅在Launcher界面上面显示的icon被修改了,setting和系统安装应用界面等还是原来的图标。

通过BubbleTextView.java修改

BubbleTextView.java这个类在Launcher运行阶段属于比较晚的,所以如果说有大量第三方应用图标需要替换的话,在Launcher启动时可能会出现卡顿。

代码路径:Launcher3/src/com/android/launcher3/BubbleTextView.java

基于Android9:

private void applyIconAndLabel(ItemInfoWithIcon info) { //FastBitmapDrawable iconDrawable = DrawableFactory.get(getContext()).newIcon(info); String pkg = info.getIntent().getComponent().getPackageName(); if("com.android.vending".equals(pkg)){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.player); BitmapDrawable clock_drawable = new BitmapDrawable(bitmap); if(clock_drawable!=null)setIcon(clock_drawable); }else if("com.android.chrome".equals(pkg)){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.chrome); BitmapDrawable clock_drawable = new BitmapDrawable(bitmap); if(clock_drawable!=null)setIcon(clock_drawable); }else{ FastBitmapDrawable iconDrawable = DrawableFactory.get(getContext()).newIcon(info); setIcon(iconDrawable); } mBadgeColor = IconPalette.getMutedColor(info.iconColor, 0.54f); //setIcon(iconDrawable); setText(info.title); if (info.contentDescription != null) { setContentDescription(info.isDisabled() ? getContext().getString(R.string.disabled_app_label, info.contentDescription) : info.contentDescription); } }

基于Android13:

代码路径:packages/apps/Launcher3/src/com/android/launcher3/BubbleTextView.java

import android.graphics.Bitmap; import android.graphics.BitmapFactory; ... ... @UiThread protected void applyIconAndLabel(ItemInfoWithIcon info) { boolean useTheme = mDisplay == DISPLAY_WORKSPACE || mDisplay == DISPLAY_FOLDER || mDisplay == DISPLAY_TASKBAR; int flags = useTheme ? FLAG_THEMED : 0; if (mHideBadge) { flags |= FLAG_NO_BADGE; } FastBitmapDrawable iconDrawable = info.newIcon(getContext(), flags); mDotParams.appColor = iconDrawable.getIconColor(); mDotParams.dotColor = getContext().getResources() .getColor(android.R.color.system_accent3_200, getContext().getTheme()); //add //setIcon(iconDrawable); String pkg = info.getIntent().getComponent().getPackageName(); String cls = info.getIntent().getComponent().getClassName(); if("com.android.vending".equals(pkg)){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.BS_player); setIcon(new FastBitmapDrawable(bitmap)); }else if("com.android.chrome".equals(pkg)){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.BS_chrome); setIcon(new FastBitmapDrawable(bitmap)); }else if("com.google.android.apps.nbu.files".equals(pkg)){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.BS_files); setIcon(new FastBitmapDrawable(bitmap)); }/* else if("com.android.fmradio".equals(pkg)){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.BS_fmradio); setIcon(new FastBitmapDrawable(bitmap)); }else if("com.android.gallery3d.app.GalleryActivity".equals(cls)){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.BS_gallery); setIcon(new FastBitmapDrawable(bitmap)); }else if("com.cooliris.media.Gallery".equals(cls)){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.BS_video); setIcon(new FastBitmapDrawable(bitmap)); }else if("com.android.soundrecorder".equals(pkg)){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.BS_soundrecorder); setIcon(new FastBitmapDrawable(bitmap)); }else if("com.android.deskclock".equals(pkg)){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.BS_deskclock); setIcon(new FastBitmapDrawable(bitmap)); }else if("com.android.calendar".equals(pkg)){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.BS_calendar); setIcon(new FastBitmapDrawable(bitmap)); }else if("com.android.music".equals(pkg)){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.BS_music); setIcon(new FastBitmapDrawable(bitmap)); }else if("com.android.calculator2".equals(pkg)){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.BS_calculator2); setIcon(new FastBitmapDrawable(bitmap)); } */else{ setIcon(iconDrawable); } //add applyLabel(info); } 通过IconCache.java修改

通过IconCache.java修改第三方应用图标,相比于BubbleTextView运行的更早并且可以单独修改应用图标的大小。

代码路径:Launcher3/src/com/android/launcher3/IconCache.java

基于Android9:

import android.support.v4.content.ContextCompat; protected CacheEntry cacheLocked( @NonNull ComponentName componentName, @NonNull Provider infoProvider, UserHandle user, boolean usePackageIcon, boolean useLowResIcon) { Preconditions.assertWorkerThread(); ComponentKey cacheKey = new ComponentKey(componentName, user); CacheEntry entry = mCache.get(cacheKey); if (entry == null || (entry.isLowResIcon && !useLowResIcon)) { entry = new CacheEntry(); mCache.put(cacheKey, entry); // Check the DB first. LauncherActivityInfo info = null; boolean providerFetchedOnce = false; if (!getEntryFromDB(cacheKey, entry, useLowResIcon) || DEBUG_IGNORE_CACHE) { info = infoProvider.get(); providerFetchedOnce = true; if (info != null) { LauncherIcons li = LauncherIcons.obtain(mContext); li.createBadgedIconBitmap(getFullResIcon(info), info.getUser(), info.getApplicationInfo().targetSdkVersion).applyTo(entry); li.recycle(); } else { if (usePackageIcon) { CacheEntry packageEntry = getEntryForPackageLocked( componentName.getPackageName(), user, false); if (packageEntry != null) { if (DEBUG) Log.d(TAG, "using package default icon for " + componentName.toShortString()); packageEntry.applyTo(entry); entry.title = packageEntry.title; entry.contentDescription = packageEntry.contentDescription; } } if (entry.icon == null) { if (DEBUG) Log.d(TAG, "using default icon for " + componentName.toShortString()); getDefaultIcon(user).applyTo(entry); } } } if (TextUtils.isEmpty(entry.title)) { if (info == null && !providerFetchedOnce) { info = infoProvider.get(); providerFetchedOnce = true; } if (info != null) { entry.title = info.getLabel(); entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user); } } } /* if("com.google.android.inputmethod.latin".equals(componentName.getPackageName().toString())) { LauncherIcons li = L


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3