2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
アダプティブ アイコンを実装する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
アダプティブ アイコンはデバイス内で一貫した形状を維持しますが、デベロッパーから提供される 1 つのアイコン アセットを基にデバイスごとに形状を変えます。さらに、ユーザーが視覚的に楽しめるモーションを付加できるよう、それに使用する 2 つのレイヤ(前景と背景)をサポートしています。
デバイスの実装者は、デバイス上のすべてのアイコンの形状を決定するデバイスマスクを提供します。このアイコンは、ランチャー アイコンを使用する任意のシステム UI サーフェス(例: ランチャー、最近、設定、共有シート)で使用されます。
例とソース
コード例:
platform/development/samples/AdaptiveIconSample/
デベロッパー向けドキュメント
ソースコード:
platform/frameworks/base/graphics/java/android/graphics/drawable/AdaptiveIconDrawable.java
実装
プラットフォーム上のアイコンの形状を変更するには、framework/base/core/res/res/values/config.xml
の 1 つの文字列を次のようにオーバーレイします。
<!-- Specifies the path that is used by AdaptiveIconDrawable class to crop launcher icons. -->
<string name="config_icon_mask" translatable="false">"M50,0L100,0 100,100 0,100 0,0z"</string>
文字列の形式と構文は、W3C による SVG 標準のパス定義に従います。PathData のこの形式は、Android ベクター型ドローアブルでもサポートされています。
このパスは凸形状で、ビュー境界内のセーフゾーン(66/71 = 91%)を確保する必要があります。これは、CTS テストで強制適用されます。
サークルをプラットフォームのマスクとして使用する場合は、config_useRoundIcon = true もオーバーレイする必要があります。使用しない場合は、この構成値を false に設定するか、この構成値を指定しないでください。
Adaptive Icon API
AdaptiveIconDrawable
クラスの API は次のとおりです。
package android.graphics.drawable;
public class AdaptiveIconDrawable extends Drawable implements Drawable.Callback {
method public Drawable getBackground();
method public Drawable getForeground();
method public Path getIconMask();
method public Region getSafeZone();
method public float getExtraInsetFraction();
method public int getOpacity();
method public void invalidateDrawable(Drawable);
method public void scheduleDrawable(Drawable, Runnable, long);
method public void setAlpha(int);
method public void setColorFilter(ColorFilter);
method public void setOpacity(int);
method public void unscheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable);
}
public class Icon extends Parceleable {
method public Bitmap createWithAdaptiveBitmap();
}
リファレンス実装
システム UI サーフェス上の静的なアダプティブ アイコンをレンダリングするために必要な操作はありません。PackageManager がドローアブルを返す場合は、単に ImageView にバインドします。このようにして、Pre-O プラットフォームでアイコンはレンダリングされます。
動的モーション効果のレンダリングについては、O-MR1 でその効果を実現する方法を示したリファレンス実装が、Launcher3(platform/packages/apps/Launcher3)に用意されます。
検証
実装を検証するには、目的のマスクをオーバーライドした後に、Launcher3、設定、最近および設定で、アイコンが正しくレンダリングされるかどうかを確認します。
また、グラフィックの CTS TestCase で、AdaptiveIconDrawableTest.java と AdaptiveIconMaskTest.java を実行して実装をテストすることもできます。
推奨の手動テストケースについては、platform/development/samples/AdaptiveIconSample/ をご覧ください。
既知の問題
既知の問題には次のものがあります。
- マスクパスの定義方法によってアイコンが不鮮明になる。
- アプリ デベロッパーが
Icon.createWithAdaptiveBitmap()
メソッドを使用しない、またはこのメソッドを適切に使用していない場合にショートカット アイコンが拡大される。このメソッドを正しく機能させるには、渡されたビットマップの上下左右に 25% のパディングが必要です。
これらの問題は次のように解決できます。
- マスクは [0, 100] x [0, 100] 座標系で定義する必要があります。
- アダプティブ アイコンに使用する画像(ランチャー アイコン、ショートカット)の上下左右に十分なパディング(25%)があることを確認します。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-27 UTC。"],[],[],null,["# Implement adaptive icons\n\nAdaptive Icons maintain a consistent shape intra-device but vary from device to\ndevice with only one icon asset provided by the developer. Additionally, icons\nsupport two layers (foreground and background) that can be used for motion to\nprovide visual delight to users.\n\n\nDevice implementers provide a device mask that will decide the shape of all icons on a\ndevice. This icon will be used on any system UI surfaces that use Launcher Icons\n(e.g., launcher, overview, settings and share sheet).\n\nExamples and source\n-------------------\n\n\nCode examples:\n\n- `platform/development/samples/AdaptiveIconSample/`\n\n\nDeveloper documentation:\n\n- [Adaptive icons](https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive)\n- [AdaptiveIconDrawable](https://developer.android.com/reference/android/graphics/drawable/AdaptiveIconDrawable.html)\n- [createWithAdaptiveBitmap](https://developer.android.com/reference/android/graphics/drawable/Icon.html#createWithAdaptiveBitmap(android.graphics.Bitmap))\n\n\nSource code:\n\n- `platform/frameworks/base/graphics/java/android/graphics/drawable/AdaptiveIconDrawable.java`\n\nImplementation\n--------------\n\n\nTo change the shape of the icon on a platform, overlay one string in\n`framework/base/core/res/res/values/config.xml`, as follows: \n\n```ecl\n\u003c!-- Specifies the path that is used by AdaptiveIconDrawable class to crop launcher icons. --\u003e\n \u003cstring name=\"config_icon_mask\" translatable=\"false\"\u003e\"M50,0L100,0 100,100 0,100 0,0z\"\u003c/string\u003e\n```\n\n\nThe format and syntax of the string follow the [W3, SVG standard for path\ndefinition](https://www.w3.org/TR/SVG/paths.html). This format for PathData is what Android vector drawables\nsupport as well.\n\n\nThis path should be convex and should respect the safezone (66/71 = 91%) within\nthe view bounds. This is enforced in one of the CTS tests.\n\n\nIf you decide to use a circle as the platform mask, make sure to also overlay\nconfig_useRoundIcon = true. If not, set this config value false or do not\nspecify this config value.\n\nAdaptive Icon API\n-----------------\n\n\nThe API for the `AdaptiveIconDrawable` class is shown below: \n\n```gdscript\npackage android.graphics.drawable;\n public class AdaptiveIconDrawable extends Drawable implements Drawable.Callback {\n method public Drawable getBackground();\n method public Drawable getForeground();\n method public Path getIconMask();\n method public Region getSafeZone();\n method public float getExtraInsetFraction();\n method public int getOpacity();\n method public void invalidateDrawable(Drawable);\n method public void scheduleDrawable(Drawable, Runnable, long);\n method public void setAlpha(int);\n method public void setColorFilter(ColorFilter);\n method public void setOpacity(int);\n method public void unscheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable);\n }\n``` \n\n```gdscript\npublic class Icon extends Parceleable {\n method public Bitmap createWithAdaptiveBitmap();\n }\n```\n\nReference implementation\n------------------------\n\n\nNothing needs to be done to render the static adaptive icons on any of the\nSystem UI surfaces. When PackageManager returns a drawable, simply bind that to\nan ImageView. This is how icons are already rendered in Pre-O platforms.\n\n\nRegarding rendering dynamic motion effect, Launcher3\n(platform/packages/apps/Launcher3) will have a reference implementation showing\nhow to achieve the effect in O-MR1.\n\nValidation\n----------\n\n\nTo validate the implementation, after overriding the mask of their liking, see\nif icons are rendered correctly in Launcher3, Settings, Overview and Settings.\nYou may also run AdaptiveIconDrawableTest.java and AdaptiveIconMaskTest.java\ninside graphics CTS TestCase to test the implementation.\n\n\nA recommended manual test case can be found at:\nplatform/development/samples/AdaptiveIconSample/.\n\nKnown issues\n------------\n\n\nKnown issues include the following:\n\n- Blurry icons, depending on how the mask path is defined.\n- Zoomed-in shortcut icons if app developers do not use the `Icon.createWithAdaptiveBitmap()` method, or do not use this method properly. For this method to function properly, the passed in Bitmap should be padded 25% on all four sides.\n\n\nThese issues can be addressed as follows:\n\n- The mask should be defined in \\[0, 100\\] x \\[0, 100\\] coordinate system.\n- Make sure that images used for adaptive icons (launcher icons , shortcuts) have sufficient padding (25%) on all four sides."]]