如何从Android磨损并发症提供商在表盘上绘制图标?

Mic*_*ovo 4 android android-wear-data-api android-wear-2.0 android-wear-complication wear-os

使用Complications API有一个图标类型,但是在绘制图标时我不知道该怎么做.

当我绘制实际的表盘时,似乎没有drawIcon方法.例如像canvas.drawIcon(icon).我只能看到如何绘制位图.

在我的drawComplications方法中我有这个:

} else if (complicationData.getType() == ComplicationData.TYPE_ICON) {
                Icon icon = complicationData.getIcon();
Run Code Online (Sandbox Code Playgroud)

然后我如何将图标绘制到画布?

这里的代码实验室没有告诉我们如何绘制图标:https://codelabs.developers.google.com/codelabs/complications/index.html?index =..% 2F..%2Findex#3

我可以只将所有drawable复制到本地可穿戴模块,并通过传入一个字符串绕过图标​​类型,然后从那里绘制相应的位图.但必须有一种方法可以从图标中提取,否则为什么会这样呢?

我也无法从谷歌搜索中找到如何将图标转换为位图,但这似乎也很愚蠢,因为我不得不首先将位图转换为图标,因为API需要一个图标.

任何帮助赞赏.

谢谢.

Mic*_*ovo 5

好的,所以我不知道我是怎么错过这个但是它很简单

Drawable drawable = icon.loadDrawable(getApplicationContext());
Run Code Online (Sandbox Code Playgroud)

然后就这样做,你可能已经知道了:

if (drawable instanceof BitmapDrawable) {
    Bitmap bitmap;
    bitmap = ((BitmapDrawable) drawable).getBitmap();
    canvas.drawBitmap(bitmap, complicationsX, mTopComplicationY, null);
}
Run Code Online (Sandbox Code Playgroud)

我在这儿看

https://developer.android.com/reference/android/graphics/drawable/Icon.html#loadDrawable(android.content.Context)

然后看到它,并想知道为什么我没有尝试过.

编辑响应评论:如果您想使用VectorDrawable,则根据需要进行调整.