<?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 Goran Luketic on Medium]]></title>
        <description><![CDATA[Stories by Goran Luketic on Medium]]></description>
        <link>https://medium.com/@goran.luketic_38701?source=rss-38c83182a29------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*40A-FFWp6bzNPVWU.jpg</url>
            <title>Stories by Goran Luketic on Medium</title>
            <link>https://medium.com/@goran.luketic_38701?source=rss-38c83182a29------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 22:05:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@goran.luketic_38701/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[How to Implement Day/Night Mode in Your Android App]]></title>
            <link>https://medium.com/cobe-mobile/how-to-implement-day-night-mode-in-your-android-app-2f21907f9b0a?source=rss-38c83182a29------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f21907f9b0a</guid>
            <category><![CDATA[night]]></category>
            <category><![CDATA[dark]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[themes]]></category>
            <dc:creator><![CDATA[Goran Luketic]]></dc:creator>
            <pubDate>Thu, 06 Jun 2019 14:11:55 GMT</pubDate>
            <atom:updated>2019-06-07T06:43:10.862Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h-JMeUXPtxpf9CbBImx40A.png" /></figure><h4>Find out the easiest way to do it yourself.</h4><p>Since Android Pie (9.0) introduced the dark/light (day/night) theme to its users, a lot of the most popular apps have welcomed this feature with open arms. And so did we. Considering we like trying out new things, we decided to give it a go and implement this feature into one of our apps too.</p><p>In the simplest way possible, I will describe the process of implementing the dark/light themes inside an app, using the AppCompat library from AndroidX libraries — if you want to do the same, don’t go anywhere.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl0HlKrB02QY0f1mbm%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl0HlKrB02QY0f1mbm%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fl0HlKrB02QY0f1mbm%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/af36c106e079259916861c2af596fd4b/href">https://medium.com/media/af36c106e079259916861c2af596fd4b/href</a></iframe><p>Before we start, here’s a suggestion: in case you’re working on any new projects, it’s highly recommended you use the AndroidX libraries. Also, if you haven’t done it already, you should consider transferring your existing projects to AndroidX as well.</p><h4>Now, let’s start</h4><p>First, import the latest AppCompat from the AndroidX libraries:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1632fc4601847e3a0855bf17eab96e2/href">https://medium.com/media/f1632fc4601847e3a0855bf17eab96e2/href</a></iframe><p>This version of AppCompat will bring new updates and bug fixes regarding the DayNight theme.<br>Then, change your theme to extend from “Theme.AppCompat.DayNight”. Here’s an example of ours:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b63a076d032d83282d6489bde1c725e/href">https://medium.com/media/8b63a076d032d83282d6489bde1c725e/href</a></iframe><h4>Moving on to some coding</h4><p>Change the current theme during the app startup (it’s recommended to set it inside the Android Application Class). From <strong>v1.1.0-aplha05</strong> this method will apply changes to any running activities, but it will also be preserved across configuration changes so there will be no need to call <strong>recreate()</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ee80e724b162baaeded5a90e1c73881/href">https://medium.com/media/3ee80e724b162baaeded5a90e1c73881/href</a></iframe><p>These are the four modes we use inside our app for the theme selection:</p><p><strong>MODE_NIGHT_NO</strong> — sets light/day theme<br><strong>MODE_NIGHT_YES</strong> — sets dark/night theme<br><strong>MODE_NIGHT_AUTO_BATTERY</strong> — changes to the dark theme if the device has the battery saver feature enabled. This mode is available from v1.1.0-alpha03.<br><strong>MODE_NIGHT_FOLLOW_SYSTEM</strong> — uses system theme (introduced in Android 9 (Pie)<br><strong>MODE_NIGHT_AUTO_TIME</strong> and <strong>MODE_NIGHT_AUTO</strong> — sets the theme depending on device time, but this mode is deprecated from v1.1.0-alpha03 so we don’t use it in our app.</p><p>Inside the app there’s a RadioGroup for switching between different themes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/462411a9292a17380dd4c72cf60c0522/href">https://medium.com/media/462411a9292a17380dd4c72cf60c0522/href</a></iframe><p>This is what it looks like on the device:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*a_T9KQn5Nh6ATZZBATWWlA.png" /><figcaption>Dark/Light theme</figcaption></figure><p>Don’t forget that the system theme only supports the Android Pie (9.0) version, so you need to remove the system theme option from UI for previous Android versions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85d874fac1080eb916bb7abb9abbcee9/href">https://medium.com/media/85d874fac1080eb916bb7abb9abbcee9/href</a></iframe><h4>Checking the current system theme</h4><p>A snippet from our app:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f05ce727aed3ffd7f3f7aba885fb424c/href">https://medium.com/media/f05ce727aed3ffd7f3f7aba885fb424c/href</a></iframe><p>Note that the configuration returns <em>only </em>if there is a night or day theme (or undefined), but we don’t know if this is set by the system, battery or manually. So we use shared preferences to store the selected theme and to check the right checkbox. Check out the complete code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4445d24d57d21a0733e537cbf95d19cd/href">https://medium.com/media/4445d24d57d21a0733e537cbf95d19cd/href</a></iframe><p>When the app runs for the first time, in shared preferences will be an undefined state. In this case, we’ll check if we have a theme from the configuration. If not, we are going to use the light theme by default.</p><h4>More control? Yes, please!</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F10rsLtGrOcCR0s%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F10rsLtGrOcCR0s%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F10rsLtGrOcCR0s%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="287" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c433de5373eb186c0b016cd6e364f8d/href">https://medium.com/media/8c433de5373eb186c0b016cd6e364f8d/href</a></iframe><p>If you want to use custom colors for the dark/light theme (E.g., a dark blue for the night and a light blue for the day theme), start by creating a folder “values-night” and override the colors file. Here you can also override styles.xml and use custom attributes if you want. This way, the app will always use colors from “values-night” when the dark theme is configured and vice versa. You can also provide alternate resources for night UI. For example, drawable-night.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AkaO5V5_JRQXpU_l8mBqIg.png" /></figure><p>You can find the <strong>complete source code</strong> here:<br><a href="https://github.com/cobeisfresh/themes-sample-android">https://github.com/cobeisfresh/themes-sample-android</a></p><h3>Recap</h3><p>Implementing the dark/light theme isn’t that complicated, especially with the new AppCompat library. There can be some additional work if you want to have more control over colors and styles, but the key is in preparation. Also, my advice is, if you’re planning on implementing this inside your project, do it right away — before kicking off the project. <br>Now let’s hear from you, have you already tried implementing it in one of your apps too?</p><p>Also, if you have any questions, feel free to leave me a comment :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*mJhwNuENsh0VEF4fHggU1A.gif" /><figcaption>I’m just going to leave this here</figcaption></figure><p><em>Goran is an Android developer at COBE, working in Kotlin and Java. When he’s not busy with native Android apps, he likes to learn new stuff so currently, he is implementing some apps in Flutter. Besides software, he’s not afraid of resistors, semiconductors or transistors so he likes to build some hardware stuff, especially audio power amplifiers. Or when he is not into software or hardware, he likes to ride a bicycle and relax with his family.</em></p><p>Like what you read? Hit like and recommend us! And if you want to continue learning, check out some other cool articles from our team:</p><ul><li><a href="https://medium.cobeisfresh.com/scrumfaces-update-youve-asked-we-delivered-e20ada0cf597">ScrumFaces Update - You&#39;ve asked, we delivered.</a></li><li><a href="https://medium.cobeisfresh.com/how-playing-sports-can-help-your-future-career-451a9ca8f356">How Playing Sports Can Help Your Future Career</a></li><li><a href="https://medium.cobeisfresh.com/how-we-got-the-whole-team-to-practice-qa-for-a-month-25c5d016a61a">How We Got the Whole Team to Practice QA for a Month</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f21907f9b0a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cobe-mobile/how-to-implement-day-night-mode-in-your-android-app-2f21907f9b0a">How to Implement Day/Night Mode in Your Android App</a> was originally published in <a href="https://medium.com/cobe-mobile">COBE</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>