Android ChipGroup IllegalArgumentException,即使使用 MaterialComponents 主题

Android ChipGroup IllegalArgumentException, even though using MaterialComponents theme

我在 AppCompatActivity 中使用 com.google.android.material.chip.ChipGroup,但是当我尝试制作 Chip 时,我得到 java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).。我已经尝试了所有可能的 Theme.MaterialComponents 主题(是的,甚至是 .Bridge),但我仍然遇到错误。在应用程序的其他地方,我也在使用芯片组并制作新芯片,一切正常。我在这里错过了什么?

MyActivity 中的相关内容:

Chip chip = new Chip(getApplicationContext());

与 MyActivity 相关 xml:

<com.google.android.material.chip.ChipGroup
    android:id="@+id/filter_chips"
    android:layout_width="0dp"
    android:layout_height="wrap_content"/>

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.appname">
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:networkSecurityConfig="@xml/network_security_config"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppName">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="MyActivity"/>
        <uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />
    </application>
</manifest>

风格:

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.AppName" 
        parent="Theme.MaterialComponents.Light.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>
    </style>
</resources>

不要使用应用程序上下文,使用 activity 的上下文。应用程序上下文中没有启用 material 主题。