<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Víctor Espejo on Medium]]></title>
        <description><![CDATA[Stories by Víctor Espejo on Medium]]></description>
        <link>https://medium.com/@victorespejo?source=rss-b4787a0ff9fa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Víctor Espejo on Medium</title>
            <link>https://medium.com/@victorespejo?source=rss-b4787a0ff9fa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:39:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@victorespejo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Design System foundations: an Android resource architecture before Compose]]></title>
            <link>https://medium.com/bestsecret-tech/design-system-foundations-an-android-resource-architecture-before-compose-4bfa749dbed0?source=rss-b4787a0ff9fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bfa749dbed0</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[apps]]></category>
            <dc:creator><![CDATA[Víctor Espejo]]></dc:creator>
            <pubDate>Tue, 11 Oct 2022 08:53:32 GMT</pubDate>
            <atom:updated>2022-10-11T08:53:32.443Z</atom:updated>
            <content:encoded><![CDATA[<p>In our company we want to establish a complete Design System that represent the look &amp; feel of our organization, and, since we do not have a resource architecture in our app, we already have a clear first step.</p><p>This resource architecture must fulfilled three conditions:</p><ul><li>Change the way we want to communicate with our users.</li><li>Keeping the cohesion of the app.</li><li>The two others must be accomplished without putting much daily effort.</li></ul><blockquote><strong><em>Note: </em></strong>It can be much more easier done if you are working with Compose, but since it is not very widespread in our app, we will work with the preCompose approach.</blockquote><p>So knowing that, we are going to evolve the way we set our visual features in a screen in order to visualize the differences between them.</p><h3>First step</h3><p>The first time we try to make an Android app, the views in our .xml files tends to run like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fa4811d3477ed64a464f89404058366/href">https://medium.com/media/5fa4811d3477ed64a464f89404058366/href</a></iframe><p>Well, it looks a bit messy, but it is the <strong>ONLY</strong> way to customize the view, right… <strong>RIGHT!?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*Qh_0jTDYgoVlW3lxYFteUw.png" /><figcaption>Just to clarify, it’s indeed a trap</figcaption></figure><p>Okay, let’s say we want to add those properties to every view in your app. Yeah, it will be such a funny work to do. Even better if this work have to be done again with UX changes… Okay, calm down, there is a solution to that, so please, close that Swift tutorial, get out of that Starbucks and continue reading.</p><h3>Coding with <em>style</em></h3><p>The first solution comes with the use of the <em>style</em>, but how can we solve this situation just changing our outfit? Well…, it’s not like that. In Android views we have a way to set a collection of properties in a view, the style.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4127b5080a60a4354eb97c118acbec19/href">https://medium.com/media/4127b5080a60a4354eb97c118acbec19/href</a></iframe><p>Okay, I know this feature is only fittable on those properties that are more generic than the canned laughter of 80’s TV shows, but it can be fixed using inheritance in order to avoid duplicity and gain consistency between views.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/564b71777ddb8f7cf0f9defe0b1431ea/href">https://medium.com/media/564b71777ddb8f7cf0f9defe0b1431ea/href</a></iframe><p>Well, that wraps it up, doesn’t it? <strong>Nope</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*aLzKS06-Q5aDxOW9RwJkrA.png" /><figcaption>Come on guys, do you really think it can’t be improved?</figcaption></figure><p>To make it on this way is a standard in Android apps development, it reduces a lot of boilerplate <strong>BUT</strong>, we still need to <strong>set the style in EVERY view</strong>. That could potentially trigger human errors, like app inconsistency, visual bugs… But on top of that, it also causes what all humans fear the most, <strong>BOREDOM</strong>.</p><h3>Coding with themes (Yes, I know this title isn’t even half good than the first latest one)</h3><p>The next step in this article is to use <em>themes</em>, and what is that? Well let’s describe it like a way to set a collection of properties into views… You might think, isn’t that the same as styles? Well yes, you are right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*uawUcRiJDeJUIg5C5GiRiQ.png" /></figure><h4>Styles vs themes</h4><p>In the same way that a polysemous word has multiple meanings but it is written the same for whatever the meaning applied; styles and themes are the same, but applied differently.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8346777b14d18e590a4a5e464adb714/href">https://medium.com/media/e8346777b14d18e590a4a5e464adb714/href</a></iframe><p>Did you get the differences?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3708651a5c0865989a66c94ca332a27d/href">https://medium.com/media/3708651a5c0865989a66c94ca332a27d/href</a></iframe><p>To sum up: styles are applied to <strong>specific views</strong> while themes are applied to <strong>view groups.</strong></p><h4>How to apply themes</h4><p>So… do we need to set the theme property on the root of every activity layout? Well, we could do it that way, but we can also set it programmatically using <strong><em>setTheme</em></strong>, but it must be done <strong>BEFORE</strong> activity inflation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a6a6ac9a3694971f4fa907f60b9bef0/href">https://medium.com/media/2a6a6ac9a3694971f4fa907f60b9bef0/href</a></iframe><p>Or, in the same way, set it the manifest activity tag.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eba482b0595c7dba1b73ed513b1152d0/href">https://medium.com/media/eba482b0595c7dba1b73ed513b1152d0/href</a></iframe><p>Okay… does that mean that we need to set a new theme for every activity? It depends, if you are going to use just one theme in your app or at least there is a dominant theme there, then you can just add the theme to the app manifest and it will be used as a base theme <strong>in every activity</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6590d814218a6488d61c4db082cf6386/href">https://medium.com/media/6590d814218a6488d61c4db082cf6386/href</a></iframe><p>You can do it both ways, but you have to ensure that <strong>before setting an activity content</strong> the activity has to have a theme that define at least the properties defined in <em>Theme.AppCompat</em> (Or <em>Theme.MaterialComponents</em> if you are using material design components), or just at least <strong>inherit from this one</strong>.</p><p>And what happens if you set a theme in the app Manifest and do it so in an activity? <strong>Theme overlay</strong> occurs, what essentially is a theme merge, but let’s talk a bit further about it.</p><h4>Theme overlay</h4><p>The theme overlay consist in a superposition of properties between two themes applied, one as a parent-theme and another as a children-theme. All the children views that have a children-theme set will have the parent-theme properties override by the children-theme properties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UvrY5-z_JkAlXn2DebevzA.png" /><figcaption>Graphic design is my passion… ok, you can visualize it better <a href="https://miro.medium.com/max/1400/0*hhaMiDxkaBW5eKra">here</a> -&gt; (Image from <a href="https://medium.com/@crafty">Nick Butcher</a>)</figcaption></figure><p>The best way to use it is defining minor themes without any inheritance that defines a little few of modifications that are commonly used in your app. The standard way to named them is ThemeOverlay.AppName.Name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be3149a449f189f773790d76a94a2496/href">https://medium.com/media/be3149a449f189f773790d76a94a2496/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*JpP3q-OIsAszZ2vCR7f6_A.png" /></figure><p>To visualize the benefits of this option we can use an example: What would you do if you have 2 themes in your application that have to be modified in the same way? If you were to use inheritance you would need to define two more themes with the same set of properties that each inherit from one of the changed themes, instead, if you were to use a themeOverlay you would only need one theme and apply it when needed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6cb1922223f080993072de7c24db18a/href">https://medium.com/media/d6cb1922223f080993072de7c24db18a/href</a></iframe><h4>How to use themes</h4><p>With our theme being applied, we just need to do the most essential thing, to use it. That means use the <strong>themes attributes</strong> instead of static values:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56d9dfcd344dd7b22b91d2f0263f0fca/href">https://medium.com/media/56d9dfcd344dd7b22b91d2f0263f0fca/href</a></iframe><p>What you get from using themes is a <strong>simple way to change your app UI</strong>. Do you want to change your app color palette? No problem, you just have to change the attributes in the theme and all will work fine, no inconsistencies, no visual bugs. It greatly helps you to define a visual standard in your app which is essential <strong>to make it easier for users to interact with the app</strong>, without dying in the process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*f5suzoJtphjUjWPgsJ8DlQ.png" /></figure><p>Indeed, this is the way Android views works, components get their properties from the actual theme, and that’s the main reason you must set a Theme that at least inherit from <em>Theme.AppCompat</em> before inflate any view, this is a hard constraint cause if not, those views can’t get anything when they are trying to retrieve the attribute properties. Likewise, when you are trying to inflate a layout that use material views, you need to use a theme that at least inherit from Theme.MaterialComponents cause material design views use an extended set of properties that doesn’t exists in <em>Theme.AppCompat</em>.</p><p>Knowing that, you can ask yourself, what can I do if I want to personalize all instances of an Android view to get a property value from a different theme property? You can rewrite the style of those components in your theme and put there the theme property that you want, instead of the default one.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecfdd132b38dfcf067ada804a6c7abd3/href">https://medium.com/media/ecfdd132b38dfcf067ada804a6c7abd3/href</a></iframe><p>But there is another question, do you can only use those properties that are already created in the themes? Nope.</p><h4>Define your own theme attributes</h4><p>You can define your own attributes and just use it as we have seen in the previous example. This definitions are commonly written in a <em>attrs.xml</em> files, and they are not only defined for themes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/acdaf7c487be5ae18be43c9838231d28/href">https://medium.com/media/acdaf7c487be5ae18be43c9838231d28/href</a></iframe><p>Now that we have introduced the custom attributes, you can organize whatever structure you want in your themes, and I would like to present you a way to set up the android resources in a semantic way that can be applied either using themes, by custom attributes, or not.</p><h4>Extra: Preset — Token resource structure</h4><p>This structure consist in setting semantic values (tokens), probably many of them, dependant of hardcoded values (presets), probably a few less than the semantic ones. Let’s see an example with colors, where you can think about structure them in two main ways:</p><ul><li>Option 1: Name the colors by how/where they are used.</li><li>Option 2: Name the colors by the android role that it is gonna take.</li></ul><p>Disadvantages:</p><ul><li>Option 1: Lot of repeated values in an unstructured file hell. Avoid it at all cost.</li><li>Option 2: This is like apply Preset-Token structure to android color themes attributes. It can be ok, but we would lost the easy way to change colors in all elements semantically related, we could repeate some colors and we could not recognize the colors by name so we couldn’t recognize the app color palette easily. Moreover, this option can be a bit unflexible if we saw it from the design perception.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f99c10364664cd3550a831414cabb75/href">https://medium.com/media/4f99c10364664cd3550a831414cabb75/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c1e4028bd2f4acd76507618c81945c7/href">https://medium.com/media/6c1e4028bd2f4acd76507618c81945c7/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81e39771ce7342e861a8be3048997dc3/href">https://medium.com/media/81e39771ce7342e861a8be3048997dc3/href</a></iframe><p>What we gain doing a preset-token resource definition is basically the possibility to divide semantically the application, enabling us to change easily many elements related between them and, last but not least, knowing our the values we manage in the app by watching a controlled preset value file instead of one file plenty of duplicated values.</p><p>Now that we have defined an app based on themes, let’s go to the next level, a <strong><em>DARKER</em></strong> one indeed.</p><h4>Beating Dark S̶o̶u̶l̶s̶ mode easily</h4><p>Themes are the key to supporting dark mode, and one way to do it easily is to split theme properties into dark mode variants/invariants.</p><p>Invariant ones would be set in a “Base.Theme” while the variant ones would be set for light/dark mode in a Theme that inherits from the base one; the night variants should be defined inside android night values resource directory “values-night”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e02c510a6995531ba4d5a0808725281a/href">https://medium.com/media/e02c510a6995531ba4d5a0808725281a/href</a></iframe><p>Organizing themes just like that, we can avoid duplicate properties that are not going to be changed from one mode to another, while we separate and automatize the changes between the variant ones when a mode change happens.</p><h3>Epilogue</h3><p>From here you can have an idea on how to handle resources, styles and themes in your app, even the ones from material design themes, which are nothing more and nothing less than a customization similar on what we have explained in the article, but in a huge way, based on their UX studies and applied to the material components. If you use them properly you can have great UX behaviours without much effort. Some of those benefits are (Examples are from MaterialDesign 2):</p><ul><li>Android color tokens</li></ul><figure><a href="https://material.io/design/color/dark-theme.html#ui-application"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9y6Wlf7xIzj_aWJ3" /></a><figcaption>1. The Material Design baseline default theme<br>2. The Material Design baseline dark theme</figcaption></figure><ul><li>Android typography tokens</li></ul><figure><a href="https://material.io/design/typography/the-type-system.html#type-scale"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sCTpHwde0OHWswv0" /></a><figcaption>MDC typography tokens</figcaption></figure><ul><li>Android typography tokens</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce25aa982d242435575200fcf49b7777/href">https://medium.com/media/ce25aa982d242435575200fcf49b7777/href</a></iframe><h4>But, how are you going to know how to handle every MDC component?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*ln_Vn36s5U-kT1aRnvm7Pw.png" /></figure><p>You can get this data from three sources:</p><ul><li><a href="https://material.io/components?platform=android">You can read it from their web documentation</a></li><li>You can read the library code</li><li><a href="https://github.com/material-components/material-components-android">You can use a catalog app in order to define what you wish.</a></li></ul><h3>Final idea</h3><p><strong>To sum up, what we want is to set up your app in a way that changes can be done easily and without breaking consistency through the app. What is explained here is just the tip of the iceberg and It isn’t written in stone so feel free to experiment and share whatever you want.</strong></p><p>That’s all, I hope you found it interesting and see you later!!</p><h3>References</h3><ul><li><a href="https://medium.com/androiddevelopers/we-recommend-material-design-components-81e6d165c2dd">We Recommend Material Design Components</a></li><li><a href="https://medium.com/androiddevelopers/android-styling-themes-vs-styles-ebe05f917578">Android styling: themes vs styles</a></li><li><a href="https://medium.com/androiddevelopers/android-styling-prefer-theme-attributes-412caa748774">Android styling: prefer theme attributes</a></li><li><a href="https://medium.com/androiddevelopers/android-styling-themes-overlay-1ffd57745207">Android Styling: themes overlay</a></li><li><a href="https://medium.com/androiddevelopers/we-recommend-material-design-components-81e6d165c2dd">We Recommend Material Design Components</a></li><li><a href="https://medium.com/androiddevelopers/material-theming-with-mdc-color-860dbba8ce2f">Material Theming with MDC: Color</a></li><li><a href="https://medium.com/androiddevelopers/material-theming-with-mdc-type-8c2013430247">Material Theming with MDC: Type</a></li><li><a href="https://medium.com/androiddevelopers/material-theming-with-mdc-shape-126c4e5cd7b4">Material Theming with MDC: Shape</a></li><li><a href="https://medium.com/androiddevelopers/dark-theme-with-mdc-4c6fc357d956">Dark Theme with MDC</a></li><li><a href="https://stackoverflow.com/questions/3441396/defining-custom-attrs">Defining custom attrs</a></li></ul><h3>Tools</h3><ul><li><a href="https://material.io/design/color/the-color-system.html#tools-for-picking-colors">Material Design</a></li><li><a href="https://material.io/resources/color/#!/?view.left=0&amp;view.right=0">Color Tool - Material Design</a></li><li><a href="https://material.io/design/shape/about-shape.html#shape-customization-tool">Material Design</a></li><li><a href="https://material.io/design/typography/the-type-system.html#type-scale">Material Design</a></li><li><a href="https://fonts.google.com/">Google Fonts</a></li><li><a href="https://fonts.google.com/icons">Material Symbols and Icons - Google Fonts</a></li><li><a href="https://github.com/material-components/material-components-android/tree/master/catalog">material-components-android/catalog at master · material-components/material-components-android</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bfa749dbed0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bestsecret-tech/design-system-foundations-an-android-resource-architecture-before-compose-4bfa749dbed0">Design System foundations: an Android resource architecture before Compose</a> was originally published in <a href="https://medium.com/bestsecret-tech">BESTSECRET Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>