andorid o 设置icon改变

01-29 22:45:57.546 2096 2096 E AndroidRuntime: java.lang.IllegalArgumentException: path must be convex

01-29 22:45:57.546  2096  2096 E AndroidRuntime: at android.graphics.Outline.setConvexPath(Outline.java:284)

01-29 22:45:57.546  2096  2096 E AndroidRuntime: at android.graphics.drawable.AdaptiveIconDrawable.getOutline(AdaptiveIconDrawable.java:387)


https://stackoverflow.com/questions/44447056/convert-adaptiveicondrawable-to-bitmap-in-android-o-preview


With the new preview release yesterday I started to update my app to

this version. Part of my app is to list installed applications with the

associated icons.


Drawable drawable = mPackageManager.getApplicationIcon(packageName);

This part of the app still works. Apps like the clock, calculator or messages already support the new version of icons, so they return aAdaptiveIconDrawable.

Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();

This part doesn't work anymore. Is there any other way to convertAdaptiveIconDrawableto aBitmap? Thanks in advance.


@NonNull

private Bitmap getBitmapFromDrawable(@NonNull Drawable drawable) {

    final Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);

    final Canvas canvas = new Canvas(bmp);

    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());

    drawable.draw(canvas);

    return bmp;

}


It will also render background in the system defined shape, if you don't want to use own.

You can use it on any Drawable, so also for VectorDrawable.

It will works also on BitmapDrawable, just getBitmap() will be more memory efficient.


Android O 新特性介绍:自适应图标(Adaptive Icons)

在以前的 Android 版本中,桌面图标大小定义为 48 x 48 dp。现在你必须按照以下的规范定义你的图层大小:

- 两张图层大小都必须为 108 x 108 dp

图层中心 72 x 72 dp 范围为可视范围

- 系统会保留四周外的 36dp 范围用于生成有趣的视觉效果(如视差效果和跳动)。


http://blog.csdn.net/wangwangli6/article/details/70211002

你可能感兴趣的:(andorid o 设置icon改变)