Android widget 将支持昼夜模式的Android应用程序更新为MaterialComponents主题,但在膨胀material小部件时出现错误主题

Android widget 将支持昼夜模式的Android应用程序更新为MaterialComponents主题,但在膨胀material小部件时出现错误主题,android-widget,android-theme,material-components-android,android-night-mode,Android Widget,Android Theme,Material Components Android,Android Night Mode,编辑:进一步检查,似乎只有NightMode导致了这个崩溃,不管我是否自己明确设置,或者让Android的系统范围设置来处理它 我有一个应用程序支持使用AppCompat主题的昼夜模式。启动时,它会应用存储设置中的日间/夜间样式(用户也可以随时从应用程序中更新设置) 为此: int mode = GlobalAppSettings.getStoredSettings().nightModeEnabled() ? AppCompatDelegate.MODE_NIGHT_YES : AppComp

编辑:进一步检查,似乎只有NightMode导致了这个崩溃,不管我是否自己明确设置,或者让Android的系统范围设置来处理它

我有一个应用程序支持使用AppCompat主题的昼夜模式。启动时,它会应用存储设置中的日间/夜间样式(用户也可以随时从应用程序中更新设置)

为此:

int mode = GlobalAppSettings.getStoredSettings().nightModeEnabled() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO;
AppCompatDelegate.setDefaultNightMode(mode);
我最近决定使用material中的Chip widget来实现标记,但当我发现应用程序试图用芯片膨胀视图时,我得到了错误:

Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
我已经用我的风格更新了我的主题,使之源自材料成分,但似乎没有任何帮助。它仍然崩溃了。然后我评论道:

AppCompatDelegate.setDefaultNightMode(mode);
虽然该应用程序似乎停留在日间模式,但芯片现在已正确充气。强制日间/夜间主题的方法是否与MaterialComponents.DayNight主题不兼容

还有其他人经历过这个问题吗

我的风格:

    <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
    
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
    
            <item name="android:windowContentTransitions">true</item>
            <item name="android:windowDisablePreview">true</item>
        </style>
    
        <style name="SplashTheme" parent="AppTheme">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
            <item name="android:windowFullscreen">true</item>
            <item name="android:windowBackground">@drawable/launch_image</item>
        </style>
    
        <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />
        <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />
    
        <style name="EditText.Search" parent="Widget.AppCompat.EditText">
            <item name="colorControlNormal">@color/black_overlay</item>
            <item name="colorControlActivated">@color/black_overlay</item>
        </style>
    
        <style name="GameyeToolbarTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
            <item name="android:textColor">@color/toolbar_title_color</item>
            <item name="android:textSize">@dimen/toolbar_title_text_size</item>
        </style>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
假的
真的
真的
真的
假的
真的
真的
@可绘制/启动图像
@彩色/黑色覆盖
@彩色/黑色覆盖
@颜色/工具栏\u标题\u颜色
@尺寸/工具栏\标题\文本\大小

我最终只是直接用

android:theme="@style/Theme.MaterialComponents"
这似乎是不必要的,因为我认为它们来自材料成分。也许是材料上的缺陷

我打开一张材料票,看看他们是否有什么想法。