I can't style the title in material3 Android

52 Views Asked by At

I'm trying to make a toolbar with a bold header and set it a white color and a blue background. Only the blue background is displayed successfully. I can't understand why the header styles don't change

<style name="CustomText">
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@color/white</item>
    </style>
    <style name="CustomToolbar" parent="Widget.Material3.Toolbar">
        <item name="android:background">#03A9F4</item>
        <item name="titleTextStyle">@style/CustomText</item>
    </style>

    <style name="Base.Theme.Workshop2" parent="Theme.Material3.DayNight">
        <!-- Customize your light theme here. -->
        <item name="toolbarStyle">@style/CustomToolbar</item>
        <item name="colorPrimaryDark">#03A9F4</item>
        <!-- <item name="colorPrimary">@color/my_light_primary</item> -->
    </style>
1

There are 1 best solutions below

1
On

You need to specify that your CustomText style item is parented by TextAppearance.Material3.Title.Large, or else Android won't recognize it as a Material3-themeable item.

Changing your style file in this way will do the trick:

<style name="CustomText" parent="TextAppearance.Material3.Title.Large">
    <item name="android:textStyle">bold</item>
    <item name="android:textColor">@color/white</item>
</style>

<style name="CustomToolbar" parent="Widget.Material3.Toolbar">
    <item name="android:background">#03A9F4</item>
</style>

<style name="Base.Theme.Workshop2" parent="Theme.Material3.DayNight">
    <!-- Customize your light theme here. -->
    <item name="toolbarStyle">@style/CustomToolbar</item>
    <item name="colorPrimaryDark">#03A9F4</item>
    <!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style>