0

I use a NumberPicker in my android application of which I want to change the font, color, and font size.

I looked a bit around and found this solution here: Setting typeFace to NumberPicker

So I defined my style as follows:

<style name="NumberPickerText">
    <item name="android:textSize">24sp</item>
    <item name="android:textColorPrimary">@color/colorPrimary</item>
    <item name="android:fontFamily">@font/poppins_light</item>
</style>

and apply it to my NumberPicker as follows:

<NumberPicker
    android:id="@+id/durationPicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:descendantFocusability="blocksDescendants"
    android:theme="@style/NumberPickerText"/>

When looking at my activity in the XML design window, it looks the way I want it to look like. However, when I run the application on my phone, the color and the font size are applied as intended, but the font is not "Poppins" but the default font.

Why is my font displaying as wished in the XML design window, but appears different on Runtime? And how can I make the font appear on Runtime as wished?

Thanks a lot for your help!

Schwandes
  • 1
  • 1

1 Answers1

0

I still don't know, why this behavior occurs, but when using another method to change the font, it works. The method I used is the following: https://stackoverflow.com/a/33340382/14349772

I didn't use this solution initially, because I had an error I couldn't resolve when extending the NumberPicker Class, which I did in the same file as my ActivityMain. Creating a separate file for the CustomNumberPicker helped overcoming the error. Now everything works as intended.

Schwandes
  • 1
  • 1