-
-
Notifications
You must be signed in to change notification settings - Fork 784
Android DetailedList: use theme text colors (replace R.color.black) #3751
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some unofficial suggestions. If you disagree with any of those or can't work them out, feel free to wait for a core team member.
…no CSL; raise if missing
| def _resolve_theme_color(view, attr_id): | ||
| ctx = view.getContext() | ||
| ta = ctx.getTheme().obtainStyledAttributes([attr_id]) | ||
| try: | ||
| if not ta.hasValue(0): | ||
| # CI's emulator theme always defines textColorPrimary/Secondary, | ||
| # so this path can't be exercised there. | ||
| raise RuntimeError( # pragma: no cover | ||
| f"Required theme color attribute not found: {attr_id}" | ||
| ) | ||
| return ta.getColor(0, 0) | ||
| finally: | ||
| ta.recycle() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... is there anywhere else where we might anticipate that this function gets used? If so maybe move it into libs folder? I'm not so sure though so don't do this yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I suggest moving it to the base Widget class, and then it can also be used by the calls to getColor in DetailedList.create and Table.create. Note that self._native_activity is already a Context, so there's no need to require the existence of a View.
Problem
On Android, DetailedList currently hard-codes R.color.black for row text.
In dark mode, this makes text unreadable (black text on dark background).
Fixes #3747.
Solution
Replace the hard-coded color with theme-resolved colors:
top_text: resolved from android.R.attr.textColorPrimary
bottom_text: resolved from android.R.attr.textColorSecondary
Fallback: Color.BLACK
Screenshots with solution implemented
As pointed out by freakboy3742 when the issue was raised, the decision whether to use textColorPrimary or textColorSecondary for bottom_text requires attention to android best practice. After looking at https://m3.material.io/components/lists/specs, I landed on textColorSecondary. top_text and bottom_text seem to work like a headline and supporting text, with varying emphases on color/contrast.