nekoblog

nekoblog

ちょっとためになるブログ

Androidアプリのアダプティブアイコンに対応

概要

AndroidのOS 8.0からAdaptiveアイコン(アダプティブアイコン)というアイコンでてきました。これまでの通常のアイコン、ラウンドアイコンに加えて、アダプティブアイコンも必要になりました。アダプティブアイコンの仕方について備忘録としてまとめました。

対応の経緯

Androidのアプリの申請時、googleのフューチャー枠獲得を行おうとした際に、任意対応項目としてアダプティブ アイコンの対応が必要になりました。

詳細

アプリのランチャー アイコンがアダプティブ アイコンの形状向けに最適化されていません。空白のバックグラウンド層の上に、既存のアプリのタイルが切り取られて表示されているか、ランチャーアイコンの主要な部分がマスクの形状によって切り取られて表示されております。アダプティブ アイコン機能は Android 8.0 で導入され、OEM がデバイス上で一貫してランチャー アイコンの形状をマスクすることができるようになりました。8.0 以降搭載のデバイスでアプリのアイコンが適切に表示されるように、下記をご確認ください。

  • サイズ 108 dp x 108 dp のアセットレイヤを 2 つ用意します。
  • 前景のアイコンレイヤは、中心から 72 dp x 72 dp の範囲に焦点を置き、キャンバスの残りの部分はシステム マスキングで操作できるようにします。
  • AndroidManifest.xml と res/mipmap XML で前景と背景の要素の場所を宣言し、関連する android:icon 属性と android:drawable 属性を更新し、新しいアイコン リソースを定義します。

詳細についてはこちらをご覧ください: https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive.html https://medium.com/google-design/designing-adaptive-icons-515af294c783

対応方法

AndroidManifest.xmlandroid:icon設定を変更

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test" >
    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".MainActivity"
            android:icon="@mipmap/ic_activity"
            android:label="@string/app_name" >
            <intent-filter
                android:icon="@mipmap/ic_activity_intent_filter"
                android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

resフォルダにアイコンとxmlファイルを設定する

68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f3232393633332f63383536303366302d633964642d636164302d653862352d3632346234353036323234352e706e67.png

フォルダ名 種類 サイズ
mipmap-mdpi 中密度(従来の HVGA)ランチャー アイコン 48 × 48
mipmap-hdpi 高密度ランチャー アイコン 72 × 72
mipmap-xhdpi 超高密度ランチャー アイコン (API レベル 8以降) 96 × 96
mipmap-xxhdpi 超超高密度ランチャー アイコン (API レベル 16以降) 144 × 144
mipmap-xxxhdpi 超超高密度ランチャー アイコン (API レベル 18以降) 192 × 192

ic_launcher_round.pngic_launcher.png

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@drawable/ic_launcher_background"/>
    <foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@drawable/ic_launcher_background"/>
    <foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>

動作検証に使用した端末

まとめ

Androidのアイコン仕様を把握し、問題なく実装することが出来ました。