java.lang.IllegalArgumentException: This component requires that you specify a valid android:textAppearance attribute

后端 未结 9 1608
囚心锁ツ
囚心锁ツ 2020-12-03 09:34

I have a com.google.android.material.button.MaterialButton component in one of my layout file and I get this error when I am using the latest version of the Material Compone

相关标签:
9条回答
  • 2020-12-03 09:53

    Got stucked in this error even if my theme extends Theme.MaterialComponents. I was creating Chips like this :Chip chip = new Chip(getActivity().getBasecontext(), null, R.attr.CustomChipChoice);.

    The solution is to change it to Chip chip = new Chip(getActivity(), null, R.attr.CustomChipChoice);.

    Hope it helps.

    0 讨论(0)
  • 2020-12-03 10:01

    I have included this dependence first

    implementation 'com.google.android.material:material:1.2.0-alpha01'
    

    Than I have set my project style as bellow

     <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    
    0 讨论(0)
  • 2020-12-03 10:02

    Check if your AppTheme inherits from MaterialComponents as specified here.

    <style name="Theme.MyApp" parent="Theme.MaterialComponents.Light">
        <!-- ... -->
    </style>
    

    Remember to check all variants of styles.xml file. This was actually the issue I had.

    0 讨论(0)
  • 2020-12-03 10:04

    Does your theme extend from Theme.MaterialComponents? More info about how to ensure all the components will work correctly can be found at https://material.io/develop/android/docs/getting-started/

    0 讨论(0)
  • 2020-12-03 10:05

    I had the same problem, I changed my activity theme but it didnt resolved the issue. The i changed my main app theme from AppCompact to Theme.MaterialComponents

    <application
        android:allowBackup="true"
        android:fullBackupContent="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme2">
    <activity
            android:name=".MainActivity"
            android:label="@string/app_name"/>
    </application>
    
    0 讨论(0)
  • 2020-12-03 10:06

    If you are using any of the MaterialComponent, then your theme must extend from the following theme - Theme.MaterialComponents.Light.DarkActionBar

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    
    0 讨论(0)
提交回复
热议问题