Skip to content

[Android] Failed to inflate ColorStateList - error fix for CheckBox#24658

Merged
PureWeen merged 1 commit into
dotnet:mainfrom
kubaflo:fix-18897
Sep 9, 2024
Merged

[Android] Failed to inflate ColorStateList - error fix for CheckBox#24658
PureWeen merged 1 commit into
dotnet:mainfrom
kubaflo:fix-18897

Conversation

@kubaflo

@kubaflo kubaflo commented Sep 8, 2024

Copy link
Copy Markdown
Collaborator

Description

In the styles.xml file, I noticed that Widget.Material3.CompoundButton.CheckBox is set as the parent for MauiCheckBox. However, Maui.MainTheme has Theme.MaterialComponents.DayNight as its parent.

After changing the parent of Maui.MainTheme to Theme.Material3.DayNight.NoActionBar, the error disappeared, but I had some reservations about whether that was the right solution.

So I dug deeper and found in src/Core/AndroidNative/maui/build/intermediates/incremental/release/mergeReleaseResources/merger.xml the following code

<style name="Base.Widget.Material3.CompoundButton.CheckBox" parent="Widget.MaterialComponents.CompoundButton.CheckBox">
    
    <item name="android:textAppearance">?attr/textAppearanceBodyMedium</item>
    <item name="errorAccessibilityLabel">@string/error_a11y_label</item>
    <item name="buttonTint">@color/m3_checkbox_button_tint</item>
    <item name="buttonIconTint">@color/m3_checkbox_button_icon_tint</item>
    <item name="buttonIcon">@null</item>
</style>

Issues Fixed

Fixes #18897
Fixes #24602

Before After

@kubaflo
kubaflo requested a review from a team as a code owner September 8, 2024 16:19
@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Sep 8, 2024
<item name="android:minWidth">0dp</item>
<item name="android:minHeight">0dp</item>
<!-- remove the button tint as MAUI manages it -->
<item name="buttonTint">?attr/colorPrimary</item>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can also be set to @null

@mattleibow mattleibow Sep 9, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think colorPrimary is defined in the templates only? What will happen if you were to remove it?

Maybe @null or anything else may be better? Of does this color always exist in a plain android app with no styles or colors?

I see it at the top of the file...

@PureWeen

PureWeen commented Sep 8, 2024

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@jonathanpeppers jonathanpeppers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PureWeen
PureWeen merged commit 277ce9f into dotnet:main Sep 9, 2024
@AlleSchonWeg

Copy link
Copy Markdown
Contributor

Hi,
i updated nightly to version 8.0.90-ci.net8.24459.1 and the problem persists. Do I need manual changes in existing projects?

@MartyIX

MartyIX commented Sep 10, 2024

Copy link
Copy Markdown
Contributor

Looking at timestamps, it looks to me that 8.0.90-ci.net8.24459.1 was compiled before this fix was merged.

@AlleSchonWeg

Copy link
Copy Markdown
Contributor

Ah okay. I will try again tomorrow.

@samhouts samhouts added the fixed-in-net9.0-nightly This may be available in a nightly release! label Oct 1, 2024
@samhouts samhouts added fixed-in-9.0.0-rc.2.24503.2 and removed fixed-in-net9.0-nightly This may be available in a nightly release! labels Oct 14, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CheckBox Bug(for Android) [Android] "Failed to inflate ColorStateList" error is logged when setting Color to CheckBox

8 participants