惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
V2EX - 技术
V2EX - 技术
Jina AI
Jina AI
有赞技术团队
有赞技术团队
美团技术团队
月光博客
月光博客
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
V
V2EX
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
人人都是产品经理
人人都是产品经理
Security Latest
Security Latest
C
CERT Recently Published Vulnerability Notes
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
罗磊的独立博客
J
Java Code Geeks
博客园 - Franky
V
Vulnerabilities – Threatpost
C
CXSECURITY Database RSS Feed - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
小众软件
小众软件
P
Privacy & Cybersecurity Law Blog
量子位
T
Threatpost
T
Tailwind CSS Blog
V
Visual Studio Blog
C
Cisco Blogs
雷峰网
雷峰网
博客园 - 【当耐特】
T
Tor Project blog
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园_首页
H
Heimdal Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 聂微东
爱范儿
爱范儿
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Threat Research - Cisco Blogs
T
Troy Hunt's Blog
H
Hacker News: Front Page
T
Tenable Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint

Danb Blog

My Experience with Ubuntu Desktop 26.04 · Danb Blog Thumbnails for Orca 3MF in GNOME Files · Danb Blog Cheaper Sodastream Gas with a Big Tank · Danb Blog June 2026: What I've Been Working On · Danb Blog Running Snyk On Forgejo/Codeberg Actions · Danb Blog Tuta & Proton: An Open Source Client Does Not Result in an Open Source Service · Danb Blog May 2026: What I've Been Working On · Danb Blog 3D Printing Parts for my Greenhouse, Round 2 · Danb Blog Great Devices: Nexus 7 2013 · Danb Blog R36S Console RetroArch Stuck Menu Issue · Danb Blog April 2026: What I've Been Working On · Danb Blog Basic OpenCode Sandboxing with Docker · Danb Blog Games Played in 2025 · Danb Blog March 2026: What I've Been Working On · Danb Blog Shivam Mathur's "node-docker" Images are Awesome for PHP CI · Danb Blog February 2026: What I've Been Working On · Danb Blog Your BookStackApp project was assigned as a project for my Software Architecture course · Danb Blog My Sovol SV08 3D Printer Setup in 2026 · Danb Blog January 2026: What I've Been Working On · Danb Blog Epson Printer: The administrator password you entered was not recognized · Danb Blog Pressure to Follow Process · Danb Blog Online Shopping Email Notifications · Danb Blog My HomeLab Setup in 2026 · Danb Blog Linux Label Printing with the Phomemo D30 · Danb Blog Reporting to the CMA: Google Android Developer Verification · Danb Blog OPNsense & Dnsmasq: Responding with specific DNS servers · Danb Blog An Impromptu Introduction to ZFS Drive Replacement at 1am · Danb Blog Experience with UK Medical Cannabis for Ankylosing Spondylitis · Danb Blog Copyright Takedown for Linking to the "State of Open Source" Report · Danb Blog No, Gumroad Did Not Become Open Source Today · Danb Blog Scripting Monitors (KDE on Fedora) · Danb Blog Amber flags in Open Source & Self-Hosted Projects · Danb Blog LLMs are Directing Open Source Licensing · Danb Blog Games Played in 2024 · Danb Blog Beware of Poison in the Source · Danb Blog Common Misconceptions of the AGPL · Danb Blog Adapting GitHub action PHPUnit tests for Codeberg/Forgejo · Danb Blog Lessons from the Allotment · Danb Blog Futo, Please don't attempt to create your own Open Source Definition · Danb Blog Scripting Monitors (Gnome & Wayland on Fedora) · Danb Blog Retaining a Greenhouse Roof with 3d Printing · Danb Blog Games Played in 2023 · Danb Blog Lessons From Growing Food Indoors · Danb Blog Why the Distinction Between "Open Source" and "Source Available" is Important · Danb Blog Raspberry Pi Camera Module 3 Timelapse · Danb Blog Removing the Rear Seats on a Volvo C30 · Danb Blog Reporting Google's WEI to the CMA · Danb Blog Controlling Default GRUB Boot Option via USB · Danb Blog Creating a Video Home for FOSS Projects · Danb Blog Paying for Search · Danb Blog My Favourite Static Site Deploy Method · Danb Blog PhpStorm (JetBrains IDE) 2023 Linux Scaling · Danb Blog Synology Hibernation with Active Backup for Business and Tailscale · Danb Blog My 2023 HomeLab Setup · Danb Blog Redefining Open Source via "Commercial Open Source" · Danb Blog Moving to Mastodon · Danb Blog Gaining Sponsors · Danb Blog "This is a Low Maintenance Project" · Danb Blog Upgrading my CPU, Ryzen 2600 to 5800x · Danb Blog Migrating Google Photos to my Personal NAS · Danb Blog Scheduling Proxmox Storage to Reduce Disk Activity · Danb Blog Why the Term "Open Source" is Important · Danb Blog Lessons From Working for Myself (9 Months In) · Danb Blog Misrepresenting Open Source for Business Benefit · Danb Blog Cat Images in WebP · Danb Blog My 2022 Workstation Setup · Danb Blog Leaving my Job to Focus on Open Source (For a bit) · Danb Blog Quickly Getting Placeholder Images With Unsplash Source · Danb Blog A Thanks to Laravel for the LTS Releases · Danb Blog A Quick Overview of Unix-Style Permissions · Danb Blog The Power of currentColor · Danb Blog Dealing With Ankylosing Spondylitis Flareups · Danb Blog Hugo Verbose Dates With Suffixes · Danb Blog
Material You (Dynamic/Adaptive) Colors in Legacy Android Apps · Danb Blog
2024-03-05 · via Danb Blog

Skip to implementation

Context

So recently I decided to create a much needed update to one of my apps that I’ve left neglected, with the last update being deployed over a decade ago in 2013. This was one of my first coding projects so it was fun to revisit it, while feeling good to actually provide some maintenance for its thousands of loyal remaining users. Time had not been kind to the app, with it asking for notification preferences & full-screen mode despite those not ever being needed, as modern Android had a tricky time understand the app’s requirements.

As part of this update, I thought I’d refresh the design, moving to a new “Material You” kind of look, which allows the app to be themed dynamically based upon user preference (and often things like wallpaper colors).

Unfortunately implementing this kind of design in my app wasn’t so straightforward. What made this difficult is that I was working down to API (Supported Android versions) levels below that where this dynamic color system was introduced (I was working down to API level 24, or Android 7 Nougat). Additionally my app, being a decade old, is a “legacy” Java application, not a fancy Kotlin, Flutter or “Jetpack Compose” app. The documentation for things like colors are not only split across design theory and technical implementation, but now also across these different app build styles, which makes finding specific guidance quite a bit trickier than I remember from my early developer days. I could find bits & pieces, but I wasn’t able to connect it up for actual working code.

It likely I’ve since lost a lot of context/understand to transform the more general documentation to code. Looking back at some of the documentation, it’s now a fair bit more obvious.

Eventually though I figured how to use dynamic colors in a pleasant way, for my old Java-based app, with easy fall-backs for old Android versions:

Implementation

Here’s what I did:

First up is to follow the “Getting Started” page here to use Material Components for Android.

I then used the Material Theme Builder to create & generate out a base theme. You have to use the “Custom” tab to be able to export. I exported as “Android Views (XML)” This export included two files:

Note, I am extending a Material 3 theme which can be seen here. This may be required/important for this kind of setup, I’m not sure.

I then added this to the onCreate methods of my activities:

DynamicColors.applyToActivityIfAvailable(this);

With that done, default widgets (styled from the material theme I’m extending) will now use dynamic colors! To specifically apply colors manually in layouts/styles, you can reference these via an ?attr/<name> value, with the names aligning with the items added to you styles.xml file. Here’s an example of a background and text color:

<Button
    android:backgroundTint="?attr/colorTertiaryContainer"
    android:textColor="?attr/colorOnTertiaryContainer" />

The names align with the color roles defined as part of the Material design documentation. If it helps to have a reference, the app I applied this to can be found open source here. I figured out some of this color-specific code stuff from the Material Components Android Color Section