Cannot Render Materialbutton With Android.material:1.1.x
Solution 1:
Update3: This is finally fixed in Studio 3.5beta2! We did it guys! 🥳
Update2: I've filed an issue here: https://issuetracker.google.com/issues/132562197. Please star for visibility.
Update: This is a cleaner workaround since we don't have to litter This has stopped working for me for no apparent reason, I've had to revert to my original workaround described below.tools:style
throughout our xml layouts.
Here's a workaround till we get an actual fix, based on Gautham's discovery:
Add this style to your styles.xml
:
<!-- For the sake of xml preview not breaking --><stylename="UnelevatedButton"parent="Widget.MaterialComponents.Button.UnelevatedButton"></style>
Add it to your Button
s like so:
<Button
...
tools:style="@style/UnelevatedButton"
style="@style/ActualButtonStyle"
/>
Note that the ordering of the two is important, the tools
line needs to come first.
You can update your UnelevatedButton
to match your ActualButtonStyle
for the sake of having previews consistent with your actual runtime buttons.
Solution 2:
I'm attempting to reproduce this issue currently, but I need more information. My current hypothesis is that it's related to button elevation (based on the animation calls in the stacktrace), which is also why unelevated button works as expected.
Could you please file an issue at https://issuetracker.google.com/issues/new?component=439535&template=1121918 with the component name and description, as well as the information requested there?
Solution 3:
amitav13's solution has one major problem, when you reformat the code the default rules will rearrange all the attributes and then everything breaks again.
Instead, until this is fixed, my proposal is to create a separate application theme for using in preview windows, in this example this Theme is called AppTheme.PreviewFix. Simply select this theme in Preview / Design panes.
attrs.xml
<?xml version="1.0" encoding="utf-8"?><resources><attrname="buttonStyle"format="reference" /></resources>
styles.xml
<?xml version="1.0" encoding="utf-8"?><resources><stylename="AppTheme"parent="Theme.MaterialComponents"><itemname="colorPrimary">@color/primaryColor</item><itemname="colorPrimaryDark">@color/primaryDarkColor</item><itemname="colorSecondary">@color/secondaryColor</item><itemname="windowActionBar">false</item><itemname="windowNoTitle">true</item><itemname="buttonStyle">@style/AppTheme.Button</item></style><stylename="AppTheme.PreviewFix"parent="AppTheme"><itemname="buttonStyle">@style/AppTheme.Button.PreviewFix</item></style><stylename="AppTheme.Button"parent="Widget.MaterialComponents.Button"/><stylename="AppTheme.Button.PreviewFix"parent="Widget.MaterialComponents.Button.UnelevatedButton"/></resources>
my_layout.xml
<com.google.android.material.button.MaterialButton
style="?buttonStyle"
...
</com.google.android.material.button.MaterialButton>
Solution 4:
Set your application theme from AppCompat to MaterialComponents such as below:
Use below style:
<stylename="AppTheme"parent="Theme.MaterialComponents.Light.DarkActionBar"><!-- Customize your theme here. --><itemname="colorPrimary">@color/colorPrimary</item><itemname="colorPrimaryDark">@color/colorPrimaryDark</item><itemname="colorAccent">@color/colorAccent</item></style>
instead of
<stylename="AppTheme"parent="Theme.AppCompat.Light.DarkActionBar"><!-- Customize your theme here. --><itemname="colorPrimary">@color/colorPrimary</item><itemname="colorPrimaryDark">@color/colorPrimaryDark</item><itemname="colorAccent">@color/colorAccent</item></style>
Solution 5:
I had the same problem, I've downloaded another version of Android Studio.
It's Working Fine on A.S. 3.6 Canary 3... I'm Using API 29, and material_version = '1.1.0-alpha08'
Download it here
The last working version for my earlier Android Studio was material_version = '1.0.0'.
But it didn't have some of the new material component features, so Instead of rolling back, I decided to Update Android Studio.
Do what best suits your needs.
Cheers.
Post a Comment for "Cannot Render Materialbutton With Android.material:1.1.x"