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
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.
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>
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.
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/
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>
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>