Repository navigation
Use Material buttons on Android, and require a Material 3 theme - #4914
Conversation
Android buttons are now MaterialButtons, so they follow the app's Material theme. Background colours are applied as a tint. The Android backend now requires the Material library, and warns at startup when the app uses a Material 2 theme.
The testbed now uses Theme.Material3.DayNight, the theme Toga's Android backend requires.
Use the android-material-button branch from beeware/toga#4914 instead of a local worktree, so the app builds from a clean checkout. travertino and toga-core come from the same branch, because each Toga package pins the others to its own version.
freakboy3742
left a comment
There was a problem hiding this comment.
This is much cleaner than I was expecting - the discussion around adopting Material 3 made it sound like switching was going to require major surgery. Not only is the set of changes relatively minor, it cleans up both the messy areas of buttons (the handling of background colours, and the capitalisation of text labels).
One cleanup flagged inline. Two other pieces that need fixes:
- The examples - they all currently hard-code references to the older Material2 DarkActionBar theme
- The
tests/widgets/test_button.py::test_icontestbed test passes, but visual inspection of the test case shows a button that isn't big enough to display the icon.
Material 3 is now a requirement of the Android backend as a whole, so the Button docs don't need to repeat it.
The examples, and the Positron FastAPI bootstrap, used the Material 2 Theme.MaterialComponents.Light.DarkActionBar theme. They now use Theme.Material3.DayNight, as the testbed does.
A Material button has 24dp of padding at each side, so the fixed 68px width Toga gave icon buttons cut off the right side of the icon. Measure icon buttons natively, like text buttons, so the size includes the icon and its padding, and remove the gap Material leaves between an icon and the text, which put the icon off center.
|
Thanks! I've addressed the other two points:
The Android testbed failure on the latest push happened while Gradle was resolving dependencies, before any tests ran. It's the same Maven Central "429 Too Many Requests" failure as main's most recent run, so it needs a re-run rather than a fix. |
I've seen this in several projects over the last week. If necessary, there's a workaround in numpy/numpy-release@25a5d01. |
freakboy3742
left a comment
There was a problem hiding this comment.
Those updates are great - thanks!
* Point Toga back at upstream now the WebView fix has merged The WebView ValueError fix landed upstream as beeware/toga#4915, so the launcher and the new-project template drop the fork branch (jkingok/beeware-toga@claude/project-thread-cbqd4n) and use beeware/toga main again. uv.lock moves to 13767c2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRRpxM667mcp32Z5NTMPAd * Move Android to a Material 3 theme, which Toga now requires beeware/toga#4914 makes Toga's Android backend expect a Material 3 base theme and warn on Material 2. Use Theme.Material3.DayNight, as Toga's own examples now do, in the launcher and the new-project template. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRRpxM667mcp32Z5NTMPAd * Follow dark mode on Android: in-app pages and list icons With the Material 3 DayNight theme the app can be dark, but: - Android's WebView kept prefers-color-scheme light, and the page used light-dark(), which older WebViews (before Chrome 123) don't support. The page's colours are now plain CSS variables chosen by a media query, and on Android html_page fixes the appearance to the app's own dark_mode (Toga API, now allowed in test_ui_app_isolation). - Android's DetailedList draws row icons as they are, so the black line-art icons vanished on a dark background. They are now tinted with the theme's primary text colour, as iOS already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRRpxM667mcp32Z5NTMPAd * Drop the page palette; let the web view's own colours follow dark mode The in-app pages now set only color-scheme (both, or the app's appearance on Android) and leave text and background to the browser's defaults. Code blocks and table borders use translucent greys, and Pygments colours stay plain rules under a prefers-color-scheme query, so older web views degrade to readable light colours. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRRpxM667mcp32Z5NTMPAd * Use the Android template's main branch for Material 3 dark colours On a dark Material 3 theme, buttons drew their text and icons in the theme's default colorOnPrimary (dark purple) on Briefcase's teal colorPrimary. Briefcase's released Android template doesn't set colorOnPrimary; its main branch does, with day and night colours (briefcase-android-gradle-template#137). The launcher and the new-project template both use it, as iOS already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRRpxM667mcp32Z5NTMPAd * Keep disabled buttons' dim text on Android until Toga has the fix Toga's TextViewWidget remembers the default text colour as a single int and restores it on a style reset, dropping the theme's state list. A disabled Material button then keeps its enabled white text on the pale disabled background. Patch the method to remember getTextColors(), as jkingok/beeware-toga#3 does, installed beside android_list. Remove it once Toga has the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRRpxM667mcp32Z5NTMPAd * Tint the launcher's list icons on macOS (part of #269) The line-art icons are marked as template images, so AppKit draws them in the label colour, and in the selection's text colour on a selected row, following light and dark mode as on iOS and Android. A prototype's own icon is left in its colours. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRRpxM667mcp32Z5NTMPAd * Draw macOS list icons in the row's text colour with a DetailedList impl Marking the icons as template images did nothing: Toga's Cocoa TogaDetailedCell draws the icon itself with drawInRect, so AppKit never tints it. Instead register a DetailedList (toga.platform.register_impl) whose cell draws icons marked by the launcher in the colour Toga gives the row's text (selected or not), then draws as Toga's cell does. A prototype's own icon keeps its colours. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRRpxM667mcp32Z5NTMPAd * Say why macOS list icons aren't tinted, and register once The skip when Toga's DetailedList is already loaded now logs a warning (it was debug, so a silent failure looked like success), and a failure while tinting an icon is logged and the icon drawn as it is. Registering happens once per process, so a second launcher doesn't warn. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRRpxM667mcp32Z5NTMPAd --------- Co-authored-by: Claude <noreply@anthropic.com>
Refs #2250.
This is the first step in moving Toga's Android backend to Material 3, one widget at a time. It converts
Button, and makes the Material library and a Material 3 theme requirements oftoga-android. Converting the rest of the widgets will continue under #2250.Changes
Buttonis now acom.google.android.material.button.MaterialButton, so it follows the app's Material theme. A background color is applied as a background tint, andTRANSPARENTresets the tint to the theme's default.Widget.set_background_filter()was only used byButton, so it has been removed.toga-androidnow requires the Material package (com.google.android.material:material:1.12.0or later) and a Material 3 base theme, such asTheme.Material3.DayNight. If the app's theme is a Material 2 theme (for exampleTheme.MaterialComponents.Light.DarkActionBar), the app issues aFutureWarningwhen it starts. There is no Material 2 support code; this is intended to land as part of a major version change. If the Material package is missing, creating aButtonraises aRuntimeError, asOptionContaineralready does.base_themeis nowTheme.Material3.DayNight.Buttondocs describe the new requirements.Dependencies
This PR depends on beeware/briefcase#3168 and beeware/briefcase-android-gradle-template#137, which are both still in review. Together, they give new Briefcase projects a
Theme.Material3.DayNightbase theme, the Material dependency, and day/night colors. Toga doesn't need them to work: an app that sets a Material 3base_themeand declares the Material dependency inbuild_gradle_dependenciesworks with this PR today, as the testbed does.Testing
Backends exercised: Android, with the full testbed on an API 31 emulator (
beePhone, as in CI), usingTheme.Material3.DayNight: 514 passed, 99 skipped, 56 xfailed, 6 xpassed, with 100.0% coverage. The core test suite passes with 100% coverage, andpre-commit run --all-filespasses.The Material 2 warning branch is marked
# pragma: no cover, because the testbed can only run with one theme.PR Checklist:
Assisted-by: Claude Code (Claude Opus 5.5)