material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[TabLayout] Component and App Theme has been set with Theme.MaterialComponents but still throw error

Open popkter opened this issue 1 year ago • 2 comments

Description: I use tablayout in xml


            <TabLayout
                style="@style/QsCustomTabLayout"
                android:layout_width="wrap_content"
                android:layout_height="68px"
                android:layout_centerHorizontal="true"
                android:background="@color/transparent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:tabRippleColor="@android:color/transparent" />

QsCustomTabLayoutStyle


    <style name="QsCustomTabLayout" parent="Widget.MaterialComponents.TabLayout">
        <item name="tabTextAppearance">@style/MyTabTextAppearance</item>
        <item name="tabIndicatorColor">@color/normal_color_blue</item>
        <item name="tabIndicatorFullWidth">false</item>
        <item name="tabIndicatorHeight">4px</item>
        <item name="tabTextColor">@color/tab_text_colors</item>
        <item name="fontFamily">@string/ali_fonts_name</item>
        <item name="android:textFontWeight">700</item>
    </style>

    <style name="MyTabTextAppearance">
        <item name="android:textSize">36px</item>
        <item name="android:textStyle">bold</item>
    </style>

AppTheme


    <style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="colorPrimary">@color/transparent</item>
        <item name="colorPrimaryDark">@color/transparent</item>
        <item name="colorAccent">@color/transparent</item>
        <item name="android:statusBarColor">@color/transparent</item>
        <item name="android:navigationBarColor">@android:color/transparent</item>
        <item name="android:windowLightNavigationBar">true</item>
        <item name="android:windowAnimationStyle">@null</item>
        <item name="android:windowIsTranslucent">true</item>
    </style>

Expected behavior:

I except app will run successfully

Android API version: 30

Material Library version: com.google.android.material:1.12.0

Error:

it throw error

caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant). at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:247) at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:216) at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:144) at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:76) at com.google.android.material.tabs.TabLayout.(TabLayout.java:540) at com.google.android.material.tabs.TabLayout.(TabLayout.java:520)

popkter avatar Jul 11 '24 09:07 popkter

Hey @popkter. Let's see...your AppTheme setup looks good. What is in your AndroidManifest.xml file?

kendrickumstattd avatar Jul 11 '24 18:07 kendrickumstattd

certainly, I set up appTheme in my menifest.xml

<application
        android:name="com.android.systemui.SystemUIApplication"
        android:allowBackup="false"
        android:allowClearUserData="false"
        android:configChanges="orientation|screenSize"
        android:defaultToDeviceProtectedStorage="true"
        android:directBootAware="true"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:persistent="true"
        android:process="com.android.systemui"
        android:requestLegacyExternalStorage="true"
        android:roundIcon="@mipmap/ic_launcher"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

Hey @popkter. Let's see...your AppTheme setup looks good. What is in your AndroidManifest.xml file?

popkter avatar Jul 12 '24 05:07 popkter

Everything is looking good so far. I did some digging -- both internally and externally -- and came across this StackOverflow (linked below). What does your TabLayout initialization code look like?

Stack Overflow link: https://stackoverflow.com/questions/76931291/chip-the-style-on-this-component-requires-your-app-theme-to-be-theme-materialco

kendrickumstattd avatar Aug 29 '24 19:08 kendrickumstattd

Since there hasn't been activity for 3 weeks, I'm going to mark as resolved, but please feel free to re-open if needed. Cheers!

kendrickumstattd avatar Sep 18 '24 13:09 kendrickumstattd