1

Android documentation says androidx.wear.watchface.complications.rendering.ComplicationDrawable has textTypeface and titleTypeface attributes. But I have found no information how to use it. I have tried to pass there font resource, font-family resource but that had no effect. What do I need to pass to have effect?

Is it possible to change font style in Drawable complication?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57

3 Answers3

1

While it is not possible to change the font itself (as far as I'm aware), you are able to change the typeface. If you look at Google's watch face sample project on GitHub you can find a few complication styles in the drawable folder. Here you will see examples of how to change the typeface:

app:textTypeface="sans-serif-condensed"
app:titleTypeface="sans-serif-condensed"

I haven't been able to find a complete up-to-date list of all the available options, but some that has been working for Roboto in the past are:

"sans-serif"
"sans-serif-light"
"sans-serif-condensed"
"sans-serif-black"
"sans-serif-thin"
"sans-serif-medium"
TofferJ
  • 4,678
  • 1
  • 37
  • 49
  • Sadly. I was sure it's possible But I've found one potential solution but I haven't tried it. If it fails, I will check your answer as a solution for early 2022 – Kirill Rudnev Feb 24 '22 at 07:21
0

It is POSSIBLE to apply a custom font for a complications.

Here is how I got it (use this before render you complication - when call complication.render(canvas, zonedDateTime, renderParameters)):

ComplicationDrawable.getDrawable(context, complicationStyle)?.apply {
    activeStyle.run {
        //... other attributes
        setTextTypeface(ResourcesCompat.getFont(context!!, R.font.your_font_resource)!!)
    }
    (complication.renderer as CanvasComplicationDrawable).drawable = this
}

I understand that it is not the best implementation but it is working (tested with android 11, galaxy watch 4 one ui 4.0)

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
0

In Java, you can change the typeface, text color and background color as follows:

private final Typeface mExoBold = ResourcesCompat.getFont(getApplicationContext(), R.font.exo_semibold);
complicationDrawable.setTextTypefaceActive(mExoBold);
complicationDrawable.setTextColorActive(Color.YELLOW);
complicationDrawable.setBackgroundColorActive(Color.argb(0xFF, 0x20, 0x20, 0x20));

I haven't found a way to change the font size in this manner, though. In the case that you want to completely reformat the complication, if you're using the old complication libraries in Java try this:

ComplicationText compTitle = null, compText = null;
String title = "", text = "";

if (complicationData.getType() == ComplicationData.TYPE_SHORT_TEXT) {
    compTitle   = complicationData.getShortTitle();
    compText    = complicationData.getShortText();
}
else if (complicationData.getType() == ComplicationData.TYPE_LONG_TEXT) {
    compTitle   = complicationData.getLongTitle();
    compText    = complicationData.getLongText();
}

if (compTitle != null) {
    try { 
        title       = compTitle.getText(context, currentTimeMillis()).toString(); 
    } catch (Exception unused) { 
        title       = ""; 
    }
}

if (compText != null) {
    try { 
        text        = compText.getText(context, currentTimeMillis()).toString(); 
    } catch (Exception unused) { 
        text        = ""; 
    }
}

Now you've got the text values in String variables, and you can display them any way you'd like (and yes, I know ComplicationText is deprecated, but then again, so is ComplicationData; I haven't yet figured out how to use the new complication libraries in Java).

Nick Esposito
  • 23
  • 1
  • 4