How instagram or direct not change shape in icon l

2019-07-11 07:01发布

问题:

How instagram not change shape in your icon to different mask (circle square, teardrop) in Android oreo.

screen shot of device with instagram installed:

I create the design of icon that Android indicate in this page Designing Adaptive Icons

screen shot of device with Direct installed:

This the code!

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <receiver
        android:name=".NotificationReceiver"
        android:enabled="true"
        android:exported="false"></receiver>
</application>

回答1:

As discussed here, you can use your own shaped icon if your targetSdkLevel is below 26, however this is not a good long term solution (you will have to target 26+ by November 2018). If you want to target Oreo, your best solution is to generate a proper adaptive icon. That said, I see a lot of icons on my Pixel 2 that aren't the right shape (Google Hangouts, Firebase, Street View, Firefox, Skype, Facebook Messenger, Outlook, etc...) and many others that are just the regular icon on a white background.

The exact behavior will depend on the launcher being used, so if you rely on the launcher allowing background layer transparency or respecting an odd icon shape you can get an inconsistent icon appearance between devices.

To test, I made a test project with targetSdkLevel of 25 and only provided a square icon and ran it on an emulated Pixel 2 with Android 8.1 and got a square icon, not forced to be round like the others.

Then I upgraded to a targetSdkLevel of 27 without adding an adaptive icon and it put my square icon inside a white circle.

Note that you don't have to set your compileSdkVersion to the same value as your targetSdkVersion. You could set your compileSdkVersion to 27 and use the v27 support libraries while keeping targetSdkVersion at 25 to get a square icon (until November).

compileSdkVersion 27
defaultConfig {
    applicationId "com.example.testproject"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
}