-
-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
styledColor android.content.res.Resources$NotFoundException: Resource ID #0x0 #258
Comments
For me, 3.0.0-beta01 works as expected, so I'll need a reproducing snippet and/or additional info at the very least, @logan23. |
Sure. Sorry for the unclear description. <resources>
<attr name="test_color" format="color"/>
</resources> in theme: <item name="test_color">#E5E5E5</item> Later somewhere: val color = styledColor(R.attr.test_color) And it works, I get my color. <item name="test_color">@color/black</item> everything works well |
You mean the issue reproduces only when you are not using color reference but when you're using a literal color value? |
Yes. If that's the intention, then I just don't understand why it worked in alpha. |
@logan23 Can you test with AGP (the Android Gradle Plugin) 4.2.0-alpha16 or 4.1.1 (once it's released)? It looks like this issue: https://issuetracker.google.com/issues/170922353 |
@logan23 Did you reproduce with AGP 4.1.1+? |
@logan23 Can you answer my question, please? |
Can reproduce with AGP 7.0.0 Version 3.0.0-alpha06 works styles.xml <resources>
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="cLampOffline">#9f00</item>
</style>
</resources> attrs.xml <resources>
<attr name="cLampOffline" format="color" />
</resources> call
Values from my debugging session: (Android 11 on Emulator) StyledAttributes#Context.resolveThemeAttribute So |
Currently I've written my own utility methods as a temporary replacement fun Context.styledColor(@AttrRes color: Int) = TypedValue().also { theme.resolveAttribute(color, it, true) }.data
fun appStyledColor(@AttrRes color: Int) = appCtx.styledColor(color)
fun Fragment.styledColor(@AttrRes attr: Int) = requireContext().styledColor(attr)
fun View.styledColor(@AttrRes attr: Int) = context.styledColor(attr) |
Thanks for your comments @NEckes, I now understand the issue and why I didn't have it. Basically, you can have theme attribute values that have a direct value, not referencing a resource by its id, and that's what broke. I'll fix it in 3.0.0-rc02, hopefully coming out in a few hours. |
I published a snapshot (see instructions on the main project page) that fixes the issue, so you can try it before I make a proper release (it takes a bit longer than I anticipated because I want to handle the edge cases right with good error messages, and not just for color resources). It's built with the following revision FYI: https://github.com/LouisCAD/Splitties/tree/5b95c4bc72158c285e459a5a6a112d1f2ed08a46 |
Works on my side ✅ |
3.0.0-beta01 throw Exception
3.0.0-alpha06 works as expected
The text was updated successfully, but these errors were encountered: