Native Desktop Themes for Production Apps
A desktop app needs more than larger versions of its phone controls. Dialogs need their own windows. Title bars, scrollbars, and keyboard focus need to behave as desktop users expect. What is Codename One? Codename One is an open-source framework for building native iOS, Android, desktop, and web apps from a single Java or Kotlin codebase. Learn more at codenameone.com . Last week we introduced…
Building native desktop themes for production applications has become possible with Codename One, an open-source framework for creating native iOS, Android, desktop, and web apps using a single Java or Kotlin codebase. This week's development introduces these themes into production use.
Native desktop themes, including Fluent, Aqua, and Adwaita, offer refined controls in light and dark appearances along with default window and dialog styles. These themes can be incorporated into applications while maintaining the application's branding.
The Codename One Settings tool now supports these themes. By setting the main class to @DesktopBuild(themeMode = native), the application automatically selects the appropriate theme for the host operating system: Fluent on Windows, Aqua on macOS, and Adwaita on Linux.
To demonstrate the impact of these themes, the Settings application underwent testing with screenshots showcasing the result in each theme. These were captured on a Mac and display theme colors, borders, spacing, and light/dark styling. However, note that on Windows or Linux, the platform's default font would be used instead of the respective theme's font.
To use these themes without having to repaint each control, developers can set 'desktop.themeMode = native' in the Settings app under Build Hints. This instructs the application to opt into the native theme and automatically select the host's theme. Alternatively, explicit theme selection (e.g., 'macos.themeMode = native') can be made on the macOS-specific port.
When implementing these themes, a custom UIID should begin with the native UIID it is refining. For instance, project-specific styles can be defined within theme.css, specifying fallback values for colors that will be overridden by the native theme palette at runtime. Additionally, project-specific brand colors should be defined in #Constants, as they should override the native palette.
By following these guidelines, developers can seamlessly incorporate Codename One's native desktop themes into production applications, providing an optimal user experience on multiple platforms.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.