问题
I tried to draw icon on android watch face but did not see on watch face. I already check this link.Ref I set text on watchface for complication TYPE text but it does not set for other type like ICON,RANGED_VALUE,SMALL_IMAGE so please suggest.
I need this type icon where red mark complication. I used this code for draw text.
if (COMPLICATION_IDS[i] == RIGHT_DIAL_COMPLICATION) {
// RIGHT_DIAL_COMPLICATION calculations
int offset = (int) ((mWidth / 2) - textWidth) / 2;
complicationsX = (mWidth / 2) + offset;
canvas.drawText(
complicationMessage,
0,
complicationMessage.length(),
complicationsX,
mComplicationsY,
mComplicationPaint);
Log.e("log", "offset==" + offset + "==complicationsX==" + complicationsX);
Log.e("log", "mComplicationsY==" + mComplicationsY);
}
and use this code for image but not getting any thing.
if (COMPLICATION_IDS[i] == LEFT_DIAL_COMPLICATION) {
complicationsX = (int) ((mWidth / 2) - textWidth) / 2;
Icon icon = complicationData.getIcon();
Drawable drawable = icon.loadDrawable(getApplicationContext());
if (drawable instanceof BitmapDrawable) {
Bitmap bitmap;
bitmap = ((BitmapDrawable) drawable).getBitmap();
canvas.drawBitmap(bitmap, complicationsX, mComplicationsY, null);
}
}
回答1:
No need to create a bitmap instance, just set the drawable bounds use it's draw method:
Icon icon = complicationData.getIcon();
if(icon != null) {
Drawable drawable = icon.loadDrawable(getApplicationContext());
if(drawable != null) {
drawable.setBounds(20, 20, 50, 50); //left, top, right, bottom
drawable.draw(canvas);
}
}
来源:https://stackoverflow.com/questions/43538447/how-set-complication-on-watch-face-of-icon-ranged-value-small-image-on-android-w