添加自定义按钮样式后应用主题不更新

app theme doesn't update after adding custom button style

如标题中所述,在将“@style/CustomRadioButton”添加到 themes.xml 后,应用程序没有任何变化(顺便说一句,CustomRadioButton 样式在 activityMain 中使用时有效“style="@style/CustomRadioButton"")

themes.xml

    <style name="Theme.Covid19" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <!-- Primary brand color. -->
    <item name="colorPrimary">@color/purple_500</item>
    <item name="colorPrimaryVariant">@color/purple_700</item>
    <item name="colorOnPrimary">@color/white</item>
    <!-- Secondary brand color. -->
    <item name="colorSecondary">@color/teal_200</item>
    <item name="colorSecondaryVariant">@color/teal_700</item>
    <item name="colorOnSecondary">@color/black</item>
    <!-- Status bar color. -->
    <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
    <!-- Customize your theme here. -->
    <item name="android:radioButtonStyle">@style/CustomRadioButton</item>
</style>

<style name="CustomRadioButton" parent="Widget.AppCompat.CompoundButton.RadioButton">
    <item name="android:background">@drawable/button_background</item>
    <item name="android:button">@null</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textColor">@color/color_button_text</item>
</style>

androidManifest.xml

android:theme="@style/Theme.Covid19">

您正在使用 MaterialComponents 主题,因此根据 theming radio buttons 上的指南,您应该省略 android: 命名空间前缀:

<style name="Theme.Covid19" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    ...
    <item name="radioButtonStyle">@style/CustomRadioButton</item>
</style>