首页 > 解决方案 > 如何在画布上绘制 android.graphics.drawable.Icon?

问题描述

我吓了一跳。我确信 Icon 会表现得像任何其他可绘制对象。但我没有看到任何 draw 或 setBounds 方法。我找不到任何输出图标的示例(其中很多用于从位图创建图标)。如何在特定位置的画布上绘制 android.graphics.drawable.Icon 的东西?

标签: androidiconsandroid-canvas

解决方案


您可以使用loadDrawable(Context context)方法来获取官方文档Drawable中提到的对象

Returns a Drawable that can be used to draw the image inside this Icon, constructing it if necessary. Depending on the type of image, this may not be something you want to do on the UI thread, so consider using loadDrawableAsync instead.

Context: Context in which to load the drawable; used to access Resources, for example.

Returns : A fresh instance of a drawable for this image, yours to keep.


推荐阅读