java.lang.IllegalArgumentException: This component

2020-02-01 03:08发布

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 Components library (com.google.android.material:material:1.0.0-alpha3):

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

It wasn't present in 1.0.0-alpha1. Is this a bug in the library or should I just specify a textAppearance attribute from now?

8条回答
我只想做你的唯一
2楼-- · 2020-02-01 03:43

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/

查看更多
相关推荐>>
3楼-- · 2020-02-01 03:46

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>
查看更多
何必那么认真
4楼-- · 2020-02-01 03:50

if u want to keep using your old styles but only want to extend from 'Theme.MaterialComponents' then you can use 'Bridge'.

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorAccent</item>
        <item name="colorAccent">@color/colorPrimaryDark</item>
</style>
查看更多
Anthone
5楼-- · 2020-02-01 03:56

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.

查看更多
疯言疯语
6楼-- · 2020-02-01 04:03

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.

查看更多
相关推荐>>
7楼-- · 2020-02-01 04:03

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>
查看更多
登录 后发表回答