How do I draw android.graphics.drawable.Icon on canvas?

时间:2019-06-01 14:10:43

标签: android icons android-canvas

I'm startled. I was sure Icon will behave an any other drawable. But I don't see any draw or setBounds methods. I can't find any examples of outputting Icon(lot of them for creating one from bitmap). How do I draw something I have as android.graphics.drawable.Icon on canvas in specific place?

1 个答案:

答案 0 :(得分:0)

您可以使用loadDrawable(Context context)方法获取官方documentation

中提到的Drawable对象
  

返回一个Drawable,可用于在此Icon内绘制图像,并在必要时进行构造。根据图像的类型,这可能不是您要在UI线程上执行的操作,因此请考虑改用loadDrawableAsync。

上下文:要加载可绘制对象的上下文;例如,用于访问资源。

返回值::此图像的drawable的新实例,您保留。