TShopping

 找回密碼
 註冊
搜索
查看: 1960|回復: 0
打印 上一主題 下一主題

[教學] Android O自適應圖標和Launcher3新特性(图标形状)

[複製鏈接]
跳轉到指定樓層
1#
發表於 2018-12-4 15:25:00 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
 
Push to Facebook
自適應圖標主要用於在發射器上可以根據不同的配置顯示不同形狀的圖標,可以顯示圓形方形等形狀。

Adaptive Icons介绍對應Adaptive Icons的介紹google開發者和各路翻譯過來的網址很多,這裡貼下兩個網址僅供參考。
官方地址
翻譯地址
主要說明應用適應Adaptive Icons的注意點和方式

1。當應用targetsdk>=26,adaptive icon就会自动生效,即使資源中並並沒有指定為自適應圖標,但實際上使用自適應圖標,圖片資源是要重新修改的,如果不改,雖然自適應會生效,但效果可能不好。
如何讓應用的圖標效果更好呢?
定義一個XML作為繪製

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
  3.   <background android:drawable="@drawable/ic_launcher_background" />
  4.   <foreground android:drawable="@drawable/ic_launcher_foreground" />
  5. </adaptive-icon>
複製代碼


背景是背景圖片,前景是前景圖片
也可以這樣:
  1. <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
  2.     <background android:drawable="@color/ic_contacts_launcher_background"/>
  3.     <foreground android:drawable="@mipmap/ic_contacts_launcher_foreground"/>
  4. </adaptive-icon>
複製代碼


背景可以使用顏色定義。
2.如果應用的targetsdk <26,想用自適應圖標的話,就需要使用上述的xml,可以在mipmap-anydpi-v26文件夾中配置。
圖片中心72 x 72 dp範圍為可視範圍。系統會保留四周外的36dp範圍用於生成有趣的視覺效果(如視差效果和跳動) 。


AdaptiveIconDrawable代碼走讀
Adaptive Icon實現方式通過上述xml來定義,我們來看下他的源碼實現方式。
首先它同BitmapDrawable,AnimationDrawable等都是繼承了Drawable,核心功能就是實現drawable的draw方法。
首先看下它的構造方法:
  1. /**
  2.      * Constructor used to dynamically create this drawable.
  3.      *
  4.      * @param backgroundDrawable drawable that should be rendered in the background
  5.      * @param foregroundDrawable drawable that should be rendered in the foreground
  6.      */
  7.     public AdaptiveIconDrawable(Drawable backgroundDrawable,
  8.             Drawable foregroundDrawable) {
  9.         this((LayerState)null, null);
  10.         if (backgroundDrawable != null) {
  11.             addLayer(BACKGROUND_ID, createChildDrawable(backgroundDrawable));
  12.         }
  13.         if (foregroundDrawable != null) {
  14.             addLayer(FOREGROUND_ID, createChildDrawable(foregroundDrawable));
  15.         }
  16.     }
複製代碼


這個方法裡面獲取前景圖片和背景圖片。
我們再看下這個的實現方法
  1. /**
  2.      * The one constructor to rule them all. This is called by all public
  3.      * constructors to set the state and initialize local properties.
  4.      */
  5.     AdaptiveIconDrawable(@Nullable LayerState state, @Nullable Resources res) {
  6.         mLayerState = createConstantState(state, res);

  7.         if (sMask == null) {
  8.             sMask = PathParser.createPathFromPathData(
  9.                 Resources.getSystem().getString(R.string.config_icon_mask));
  10.         }
  11.         mMask = PathParser.createPathFromPathData(
  12.             Resources.getSystem().getString(R.string.config_icon_mask));
  13.         mMaskMatrix = new Matrix();
  14.         mCanvas = new Canvas();
  15.         mTransparentRegion = new Region();
  16.     }
複製代碼


這個方法我們重點關注一下mmask指定,這個變量就是代表的圖標的形狀。我們可以看到這個值獲取方式Resources.getSystem()。的getString(R.string.config_icon_mask)
查看這個config_icon_mask的值
  1. <!-- Specifies the path that is used by AdaptiveIconDrawable class to crop launcher icons. -->
  2.     <string name="config_icon_mask" translatable="false">"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"</string>
複製代碼


M,C,L等基本語法可以到網上搜索下。
也就是默認情況下獲取自適應圖標默認取得就是該形狀的圖標。這個應該是個圓形的樣式。
然後我們再看下AdaptiveIconDrawable的繪製方法,具體
  1. private void updateMaskBoundsInternal(Rect b) {
  2.         mMaskMatrix.setScale(b.width() / MASK_SIZE, b.height() / MASK_SIZE);
  3.         sMask.transform(mMaskMatrix, mMask);

  4.         if (mMaskBitmap == null || mMaskBitmap.getWidth() != b.width() ||
  5.             mMaskBitmap.getHeight() != b.height()) {
  6.             mMaskBitmap = Bitmap.createBitmap(b.width(), b.height(), Bitmap.Config.ALPHA_8);
  7.             mLayersBitmap = Bitmap.createBitmap(b.width(), b.height(), Bitmap.Config.ARGB_8888);
  8.         }
  9.         // mMaskBitmap bound [0, w] x [0, h]
  10.         mCanvas.setBitmap(mMaskBitmap);
  11.         mPaint.setShader(null);
  12.         mCanvas.drawPath(mMask, mPaint);

  13.         // mMask bound [left, top, right, bottom]
  14.         mMaskMatrix.postTranslate(b.left, b.top);
  15.         mMask.reset();
  16.         sMask.transform(mMaskMatrix, mMask);
  17.         // reset everything that depends on the view bounds
  18.         mTransparentRegion.setEmpty();
  19.         mLayersShader = null;
  20.     }
  21.    
  22.     @Override
  23.     public void draw(Canvas canvas) {
  24.         if (mLayersBitmap == null) {
  25.             return;
  26.         }
  27.         if (mLayersShader == null) {
  28.             mCanvas.setBitmap(mLayersBitmap);
  29.             mCanvas.drawColor(Color.BLACK);
  30.             for (int i = 0; i < mLayerState.N_CHILDREN; i++) {
  31.                 if (mLayerState.mChildren[i] == null) {
  32.                     continue;
  33.                 }
  34.                 final Drawable dr = mLayerState.mChildren[i].mDrawable;
  35.                 if (dr != null) {
  36.                     dr.draw(mCanvas);
  37.                 }
  38.             }
  39.             mLayersShader = new BitmapShader(mLayersBitmap, TileMode.CLAMP, TileMode.CLAMP);
  40.             mPaint.setShader(mLayersShader);
  41.         }
  42.         if (mMaskBitmap != null) {
  43.             Rect bounds = getBounds();
  44.             canvas.drawBitmap(mMaskBitmap, bounds.left, bounds.top, mPaint);
  45.         }
  46.     }
複製代碼

意思就是將兩張圖層抽拉先繪製上去,再根據的getBounds區域將mMaskBitmap繪製上去。當然之前還有一些區域的縮放等操作。
還得了解下BitmapShader著色器的使用方法。

啟動設置圖標形狀
先看下SettingsActivity.java中的菜單實現
  1. Preference iconShapeOverride = findPreference(IconShapeOverride.KEY_PREFERENCE);
  2.             if (iconShapeOverride != null) {
  3.                 if (IconShapeOverride.isSupported(getActivity())) {
  4.                     IconShapeOverride.handlePreferenceUi((ListPreference) iconShapeOverride);
  5.                 } else {
  6.                     getPreferenceScreen().removePreference(iconShapeOverride);
  7.                 }
  8.             }
複製代碼

由此可以看到則isSupported方法是是否支持設置圖標形狀的判斷條件。
  1. public static boolean isSupported(Context context) {
  2.         ///1.判断系统SDK 版本是否>=26
  3.         if (!Utilities.isAtLeastO()) {
  4.             return false;
  5.         }
  6.         // Only supported when developer settings is enabled
  7.         ///2.是否打开了开发者选项。如果开发者选项没打开,就看不到这个菜单。
  8.         if (Settings.Global.getInt(context.getContentResolver(),
  9.                 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 1) {
  10.             return false;
  11.         }

  12.         try {
  13.             if (getSystemResField().get(null) != Resources.getSystem()) {
  14.                 // Our assumption that mSystem is the system resource is not true.
  15.                 /// 3.大概意思就是获取不到mSystem,如果获取不到,说明当前系统存在问题
  16.                 return false;
  17.             }
  18.         } catch (Exception e) {
  19.             // Ignore, not supported
  20.             return false;
  21.         }
  22.         ///4. 获取系统中config_icon_mask的resource id
  23.         return getConfigResId() != 0;
  24.     }
複製代碼

注意點就是android 8.0設備要打開開發者選項一般就會有此功能,說明支持AdaptiveIcon。
菜單出現後,我們選擇其中一種形狀來設置。
  1. <!-- Values for icon shape overrides. These should correspond to entries defined
  2.      in icon_shape_override_paths_names -->
  3.     <string-array translatable="false" name="icon_shape_override_paths_values">
  4.         <item></item>
  5.         <item>M50,0L100,0 100,100 0,100 0,0z</item>
  6.         <item>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</item>
  7.         <item>M50 0A50 50,0,1,1,50 100A50 50,0,1,1,50 0</item>
  8.         <item>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</item>
  9.     </string-array>

  10.     <string-array translatable="false" name="icon_shape_override_paths_names">
  11.         <!-- Option to not change the icon shape on home screen. [CHAR LIMIT=50] -->
  12.         <item>@string/icon_shape_system_default</item>
  13.         <item>Square</item>
  14.         <item>Squircle</item>
  15.         <item>Circle</item>
  16.         <item>Teardrop</item>
  17.     </string-array>
複製代碼


打開可以看到一個形狀對應的值就是一個矢量圖的字符串值。
  1. private static class PreferenceChangeHandler implements OnPreferenceChangeListener {

  2.         private final Context mContext;

  3.         private PreferenceChangeHandler(Context context) {
  4.             mContext = context;
  5.         }

  6.         @Override
  7.         public boolean onPreferenceChange(Preference preference, Object o) {
  8.             String newValue = (String) o;
  9.             if (!getAppliedValue(mContext).equals(newValue)) {
  10.                 // Value has changed
  11.                 ProgressDialog.show(mContext,
  12.                         null /* title */,
  13.                         mContext.getString(R.string.icon_shape_override_progress),
  14.                         true /* indeterminate */,
  15.                         false /* cancelable */);
  16.                 new LooperExecuter(LauncherModel.getWorkerLooper()).execute(
  17.                         new OverrideApplyHandler(mContext, newValue));
  18.             }
  19.             return false;
  20.         }
  21.     }
  22.    
  23. private static class OverrideApplyHandler implements Runnable {

  24.         private final Context mContext;
  25.         private final String mValue;

  26.         private OverrideApplyHandler(Context context, String value) {
  27.             mContext = context;
  28.             mValue = value;
  29.         }

  30.         @Override
  31.         public void run() {
  32.             // Synchronously write the preference.
  33.             prefs(mContext).edit().putString(KEY_PREFERENCE, mValue).commit();
  34.             // Clear the icon cache.
  35.             LauncherAppState.getInstance(mContext).getIconCache().clear();

  36.             // Wait for it
  37.             try {
  38.                 Thread.sleep(PROCESS_KILL_DELAY_MS);
  39.             } catch (Exception e) {
  40.                 Log.e(TAG, "Error waiting", e);
  41.             }

  42.             // Schedule an alarm before we kill ourself.
  43.             Intent homeIntent = new Intent(Intent.ACTION_MAIN)
  44.                     .addCategory(Intent.CATEGORY_HOME)
  45.                     .setPackage(mContext.getPackageName())
  46.                     .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  47.             PendingIntent pi = PendingIntent.getActivity(mContext, RESTART_REQUEST_CODE,
  48.                     homeIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
  49.             mContext.getSystemService(AlarmManager.class).setExact(
  50.                     AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 50, pi);

  51.             // Kill process
  52.             android.os.Process.killProcess(android.os.Process.myPid());
  53.         }
  54.     }
複製代碼


設置的時候執行上面代碼,主要將設置的保存到本地,清除圖標緩存,然後重啟發射。

如何改變發射器上的圖標的
我們再看下上面設置的圖標形狀的值到底是怎麼使用的,如何使圖標變化的
我們找到LauncherProvider的onCreate方法裡面使用的地方。
  1. IconShapeOverride.apply(getContext());
複製代碼


看看這個申請方法:
  1. private static int getConfigResId() {
  2.         return Resources.getSystem().getIdentifier("config_icon_mask", "string", "android");
  3.     }
  4.    
  5. public static void apply(Context context) {
  6.         if (!Utilities.isAtLeastO()) {
  7.             return;
  8.         }
  9.         String path = getAppliedValue(context);
  10.         if (TextUtils.isEmpty(path)) {
  11.             return;
  12.         }
  13.         if (!isSupported(context)) {
  14.             return;
  15.         }

  16.         // magic
  17.         try {
  18.             Resources override =
  19.                     new ResourcesOverride(Resources.getSystem(), getConfigResId(), path);
  20.             getSystemResField().set(null, override);
  21.         } catch (Exception e) {
  22.             Log.e(TAG, "Unable to override icon shape", e);
  23.             // revert value.
  24.             prefs(context).edit().remove(KEY_PREFERENCE).apply();
  25.         }
  26.     }
複製代碼


其中ResourcesOverride是繼承了資源,並且重寫了的getString方法
  1. private static class ResourcesOverride extends Resources {

  2.         private final int mOverrideId;
  3.         private final String mOverrideValue;

  4.         @SuppressWarnings("deprecated")
  5.         public ResourcesOverride(Resources parent, int overrideId, String overrideValue) {
  6.             super(parent.getAssets(), parent.getDisplayMetrics(), parent.getConfiguration());
  7.             mOverrideId = overrideId;
  8.             mOverrideValue = overrideValue;
  9.         }

  10.         @NonNull
  11.         @Override
  12.         public String getString(int id) throws NotFoundException {
  13.             if (id == mOverrideId) {
  14.                 return mOverrideValue;
  15.             }
  16.             return super.getString(id);
  17.         }
  18.     }
複製代碼


再看一下getSystemResField方法
  1. private static Field getSystemResField() throws Exception {
  2.         Field staticField = Resources.class.getDeclaredField("mSystem");
  3.         staticField.setAccessible(true);
  4.         return staticField;
  5.     }
複製代碼


這個方法是反射系統資源中mSystem變量。
上面大概的意思就是Launcher中將Resources的mSystem設置成了ResourcesOverride對象,
也就是說Resources的getSystem方法獲取的是我們重寫的ResourcesOverride,當調用getString方法的時候,走的也是重寫的方法.getString方法裡面判斷瞭如果string id是config_icon_mask這個的時候,返回我們傳入的mOverrideValue,這個mOverrideValue就是用戶選擇的圖標形狀值。

  1. /**
  2.      * Return a global shared Resources object that provides access to only
  3.      * system resources (no application resources), and is not configured for
  4.      * the current screen (can not use dimension units, does not change based
  5.      * on orientation, etc).
  6.      */
  7.     public static Resources getSystem() {
  8.         synchronized (sSync) {
  9.             Resources ret = mSystem;
  10.             if (ret == null) {
  11.                 ret = new Resources();
  12.                 mSystem = ret;
  13.             }
  14.             return ret;
  15.         }
  16.     }
複製代碼


現在回頭看下AdaptiveIconDrawable的構造方法:
  1. /**
  2.      * The one constructor to rule them all. This is called by all public
  3.      * constructors to set the state and initialize local properties.
  4.      */
  5.     AdaptiveIconDrawable(@Nullable LayerState state, @Nullable Resources res) {
  6.         mLayerState = createConstantState(state, res);

  7.         if (sMask == null) {
  8.             sMask = PathParser.createPathFromPathData(
  9.                 Resources.getSystem().getString(R.string.config_icon_mask));
  10.         }
  11.         mMask = PathParser.createPathFromPathData(
  12.             Resources.getSystem().getString(R.string.config_icon_mask));
  13.         mMaskMatrix = new Matrix();
  14.         mCanvas = new Canvas();
  15.         mTransparentRegion = new Region();
  16.     }
複製代碼

此方法的Resources.getSystem()。的getString(R.string.config_icon_mask),通過的getString方法,如果ID是config_icon_mask,則返回的是mOverrideValue,mOverrideValue就是上面5種裡面的一種。
因此,啟動器獲取應用圖標的時候時候,如果該應用是支持AdaptiveIcon的話,返回的圖標就是根據形狀裁剪出來的AdaptiveIconDrawable,啟動器從系統拿到的圖標已經是想要的形狀圖標了。
看下我們啟動是如何獲取應用圖標的

  1. public Drawable getFullResIcon(LauncherActivityInfo info) {
  2.         return mIconProvider.getIcon(info, mIconDpi);
  3.     }
  4.    
  5.      public Drawable getIcon(LauncherActivityInfo info, int iconDpi) {
  6.         return info.getIcon(iconDpi);
  7.     }
複製代碼


最終調用到LauncherActivityInfo的方法調用getIcon
  1. /**
  2.      * Returns the icon for this activity, without any badging for the profile.
  3.      * @param density The preferred density of the icon, zero for default density. Use
  4.      * density DPI values from {@link DisplayMetrics}.
  5.      * @see #getBadgedIcon(int)
  6.      * @see DisplayMetrics
  7.      * @return The drawable associated with the activity.
  8.      */
  9.     public Drawable getIcon(int density) {
  10.         // TODO: Go through LauncherAppsService
  11.         final int iconRes = mActivityInfo.getIconResource();
  12.         Drawable icon = null;
  13.         // Get the preferred density icon from the app's resources
  14.         if (density != 0 && iconRes != 0) {
  15.             try {
  16.                 final Resources resources
  17.                         = mPm.getResourcesForApplication(mActivityInfo.applicationInfo);
  18.                 icon = resources.getDrawableForDensity(iconRes, density);
  19.             } catch (NameNotFoundException | Resources.NotFoundException exc) {
  20.             }
  21.         }
  22.         // Get the default density icon
  23.         if (icon == null) {
  24.             icon = mActivityInfo.loadIcon(mPm);
  25.         }
  26.         return icon;
  27.     }
複製代碼

經過試驗,系統返回的繪製,就已經是我們想要的設置的形狀圖標了。

演示驗證
下面我自己參考上述的代碼,寫個獨立的演示,看看獲取的圖標。我們可以傳任意形狀的圖形,看看返回的圖顯示情況。
我們將上面的寫在一個輔助類中代碼如下:
  1. /**
  2. * Created by LeongAndroid on 2017/11/9.
  3. */
  4. @TargetApi(Build.VERSION_CODES.O)
  5. public class IconShapeOverrideHelper {

  6.     /**
  7.      * 设置应用的新Resource
  8.      * @param path
  9.      */
  10.     public static void apply(String path) {
  11.         try {
  12.             Resources override =
  13.                     new ResourcesOverride(Resources.getSystem(), getConfigResId(), path);
  14.             getSystemResField().set(null, override);
  15.         } catch (Exception e) {
  16.             // revert value.
  17.             Log.d("IconShapeHelper", "apply exception "+e);
  18.         }
  19.     }

  20.     private static Field getSystemResField() throws Exception {
  21.         Field staticField = Resources.class.getDeclaredField("mSystem");
  22.         staticField.setAccessible(true);
  23.         return staticField;
  24.     }

  25.     private static int getConfigResId() {
  26.         return Resources.getSystem().getIdentifier("config_icon_mask", "string", "android");
  27.     }

  28.     private static class ResourcesOverride extends Resources {
  29.         private final int mOverrideId;
  30.         private final String mOverrideValue;
  31.         @SuppressWarnings("deprecated")
  32.         public ResourcesOverride(Resources parent, int overrideId, String overrideValue) {
  33.             super(parent.getAssets(), parent.getDisplayMetrics(), parent.getConfiguration());
  34.             mOverrideId = overrideId;
  35.             mOverrideValue = overrideValue;
  36.         }

  37.         @NonNull
  38.         @Override
  39.         public String getString(int id) throws NotFoundException {
  40.             if (id == mOverrideId) {
  41.                 return mOverrideValue;
  42.             }
  43.             return super.getString(id);
  44.         }
  45.     }

  46.     public static Drawable getAppIcon(PackageManager pm, String packname){
  47.         try {
  48.             ApplicationInfo info = pm.getApplicationInfo(packname, 0);
  49.             return info.loadIcon(pm);
  50.         } catch (PackageManager.NameNotFoundException e) {
  51.             // TODO Auto-generated catch block
  52.             e.printStackTrace();

  53.         }
  54.         return null;
  55.     }

  56.     /**
  57.      * 此方法可以获取应用图标的原始图
  58.      * @param mPackageManager
  59.      * @param packageName
  60.      * @return
  61.      */
  62.     public static Bitmap getAppIcon2(PackageManager mPackageManager, String packageName) {
  63.         try {
  64.             Drawable drawable = mPackageManager.getApplicationIcon(packageName);

  65.             if (drawable instanceof BitmapDrawable) {
  66.                 return ((BitmapDrawable) drawable).getBitmap();
  67.             } else if (drawable instanceof AdaptiveIconDrawable) {
  68.                 Drawable backgroundDr = ((AdaptiveIconDrawable) drawable).getBackground();
  69.                 Drawable foregroundDr = ((AdaptiveIconDrawable) drawable).getForeground();

  70.                 Drawable[] drr = new Drawable[2];
  71.                 drr[0] = backgroundDr;
  72.                 drr[1] = foregroundDr;

  73.                 LayerDrawable layerDrawable = new LayerDrawable(drr);

  74.                 int width = layerDrawable.getIntrinsicWidth();
  75.                 int height = layerDrawable.getIntrinsicHeight();

  76.                 Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

  77.                 Canvas canvas = new Canvas(bitmap);

  78.                 layerDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
  79.                 layerDrawable.draw(canvas);

  80.                 return bitmap;
  81.             }
  82.         } catch (PackageManager.NameNotFoundException e) {
  83.             e.printStackTrace();
  84.         }

  85.         return null;
  86.     }

  87. }
複製代碼

然後再寫個活性,通過標準API來獲取應用圖標,看看顯示什麼。
  1. public class AdaptiveIconActivity extends AppCompatActivity {
  2.     private static final String TAG = "AdaptiveIcon";
  3.     private ImageView imageView = null;
  4.     private ImageView imageView1 = null;
  5.     String patch = "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";
  6.     @Override
  7.     protected void onCreate(@Nullable Bundle savedInstanceState) {
  8.         super.onCreate(savedInstanceState);
  9.         setContentView(R.layout.adaptive_icon_layout);
  10.         IconShapeOverrideHelper.apply(patch);
  11.         imageView = (ImageView)this.findViewById(R.id.image);
  12.         imageView1 = (ImageView)this.findViewById(R.id.image1);
  13.         ///直接用标准接口获取图标
  14.         Drawable drawable = IconShapeOverrideHelper.getAppIcon(getPackageManager(), "com.leong.testandroido");
  15.         imageView.setImageDrawable(drawable);
  16.         ///图标原始
  17.         Bitmap bitmap = IconShapeOverrideHelper.getAppIcon2(getPackageManager(), "com.leong.testandroido");
  18.         Log.d(TAG, "origin bitmap w = "+bitmap.getWidth()+", h = "+bitmap.getHeight());
  19.         imageView1.setImageBitmap(bitmap);
  20.     }

  21. }
複製代碼


顯示效果如下:






效果圖

上面的圖就是我們返回的圖標,下面的圖是一個應用的原圖。

Demo源碼路徑:https://github.com/LeongAndroid/OLauncherNewFeature

總結
上面的方式我們可以設想下,如果Launcher3將設置的圖標形狀這個參數公開出去,那所有其他的應用都可以根據這個mMask來獲取跟Launcher3相同形狀的圖標。當然,這個就需要修改下Launcher3的代碼了,將設置的參數公開給外部應用。

文章出處https://www.jianshu.com/p/c7af54a361a2
https://www.jianshu.com/p/20df6c156f3d



 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-26 18:42 , Processed in 0.062221 second(s), 25 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表