<?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 Jamshid Mamatkulov on Medium]]></title>
        <description><![CDATA[Stories by Jamshid Mamatkulov on Medium]]></description>
        <link>https://medium.com/@jamshid-m?source=rss-a6faec57c4db------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AwfPA1ckTmxaUCjE4fFepQ.jpeg</url>
            <title>Stories by Jamshid Mamatkulov on Medium</title>
            <link>https://medium.com/@jamshid-m?source=rss-a6faec57c4db------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 02:10:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jamshid-m/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[DayNight — Applying dark mode without recreating your app]]></title>
            <link>https://proandroiddev.com/daynight-applying-dark-mode-without-recreating-your-app-c8a62d51092d?source=rss-a6faec57c4db------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8a62d51092d</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[dark-mode]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Jamshid Mamatkulov]]></dc:creator>
            <pubDate>Fri, 23 Oct 2020 13:37:50 GMT</pubDate>
            <atom:updated>2020-10-25T17:06:48.475Z</atom:updated>
            <content:encoded><![CDATA[<h3>DayNight — Applying dark mode without recreating your app</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k1Q_bmXtbCkReCMy6vUCEw.png" /><figcaption>Illustration by <a href="https://twitter.com/VPoltrack">Virginia Poltrack</a></figcaption></figure><h4>Source is available on <a href="https://github.com/Jamshid-M/DayNight">G<strong>ithub</strong></a></h4><h3>How can I avoid recreating my application?</h3><p>First of all you have to add <em>configChanges</em> mode to activity on your app Manifest file</p><pre>&lt;application<br>    android:allowBackup=&quot;true&quot;<br>    android:icon=&quot;@mipmap/ic_launcher&quot;<br>    android:label=&quot;@string/app_name&quot;<br>    android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;<br>    android:supportsRtl=&quot;true&quot;<br>    android:theme=&quot;@style/AppTheme&quot;&gt;<br>    &lt;activity android:name=&quot;.MainActivity&quot;<br>        android:configChanges=&quot;uiMode&quot;&gt; //add this line<br><br>        &lt;intent-filter&gt;<br>            &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;<br><br>            &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;<br>        &lt;/intent-filter&gt;<br>    &lt;/activity&gt;<br>&lt;/application&gt;</pre><p>This line of code will prevent recreating your app when applied dark mode manually or from notification bar, so if you have used colors-night.xml it will be skipped since your app doesn’t recreated. So all coloring stuff now in your hand.</p><h3>How can I apply colors manually?</h3><p>In my case I have created colors with <strong>“night” </strong>ending on my original colors on colors.xml</p><pre>&lt;color name=&quot;colorPrimary&quot;&gt;#fff&lt;/color&gt;<br>&lt;color name=&quot;colorPrimaryDark&quot;&gt;#fff&lt;/color&gt;<br>&lt;color name=&quot;colorAccent&quot;&gt;#D81B60&lt;/color&gt;<br>&lt;color name=&quot;colorText&quot;&gt;#1A1A1A&lt;/color&gt;<br><br><br>//night mode<br>&lt;color name=&quot;colorPrimaryNight&quot;&gt;#000&lt;/color&gt;<br>&lt;color name=&quot;colorPrimaryDarkNight&quot;&gt;#000&lt;/color&gt;<br>&lt;color name=&quot;colorTextNight&quot;&gt;#dcdcdc&lt;/color&gt;</pre><p>After altering your colors go to Activity page and override <em>onConfigurationChanged</em> method and apply your colors based on state of <em>nightModeFlags</em></p><pre>override fun onConfigurationChanged(newConfig: Configuration) {<br>    super.onConfigurationChanged(newConfig)<br>    val nightModeFlags = <em>resources</em>.<em>configuration</em>.uiMode and Configuration.<em>UI_MODE_NIGHT_MASK<br><br>    </em>if (nightModeFlags == Configuration.<em>UI_MODE_NIGHT_NO</em>){<br>        applyDayNight(OnDayNightStateChanged.DAY)<br>    }else{<br>        applyDayNight(OnDayNightStateChanged.NIGHT)<br>    }<br>}</pre><pre>private fun applyDayNight(state: Int){<br>    if (state == OnDayNightStateChanged.DAY){<br>       //apply day colors for your views<br>    }else{<br>       //apply night colors for your views<br>    }<strong><br></strong>}</pre><p><em>onConfigurationChanged </em>method will be invoked on every DayNight state change, e.g enable or disable Dark Mode from Notification bar or apply manually from code.</p><h3>I have fragments inside of my Activity, how can I notify them?</h3><p>Easy, just create interface and extend all fragments where you want apply night mode.</p><pre>interface OnDayNightStateChanged {<br><br>    fun onDayNightApplied(state: Int)<br><br>    companion object{<br>        const val DAY = 1<br>        const val NIGHT = 2<br>    }<br>}</pre><p>And extend your fragment with this interface</p><pre>class YourFragment: Fragment(), OnDayNightStateChanged {<br><br>    override fun onDayNightApplied(state: Int) {<br>        if(state == OnDayNightStateChanged.DAY){<br>            //apply day colors for your views<br>        }else{<br>            //apply night colors for your views<br>        }<br>    }<br>}</pre><p>And you have to notify your Fragments that’s it. For notifying your fragments responsible class is your Activity. On every configuration change your fragments also will get DayNight state.</p><pre>private fun applyDayNight(state: Int){<br>    if (state == OnDayNightStateChanged.DAY){<br>       //apply day colors for your views<br>    }else{<br>       //apply night colors for your views<br>    }</pre><pre>    <em>supportFragmentManager</em>.<em>fragments</em>.<em>forEach </em><strong>{<br>        </strong>if(<strong>it </strong>is OnDayNightStateChanged){<br>            <strong>it</strong>.onDayNightApplied(state)<br>        }<br>    <strong>}<br></strong>}</pre><h3>Extra: Apply Dark Mode on StatusBar and Navigation Bar</h3><p>Your status bar and navigation bar have to be also dark with white text and icons on it and vise versa on day state.</p><p>If Day mode, then add this on your <em>applyDayNight</em> method in your Activity</p><pre>if (Build.VERSION.<em>SDK_INT </em>&gt;= Build.VERSION_CODES.<em>O</em>) {<br>    if (nightModeFlags == Configuration.<em>UI_MODE_NIGHT_NO</em>) {<br>        <em>decorView</em>.<em>systemUiVisibility </em>= <em>decorView</em>.<em>systemUiVisibility </em>or View.<em>SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR<br>    </em>}<br>}<br><br>if (Build.VERSION.<em>SDK_INT </em>&gt;= Build.VERSION_CODES.<em>M</em>) {<br>    var flags: Int = <em>decorView</em>.<em>systemUiVisibility<br>    </em>flags = flags or View.<em>SYSTEM_UI_FLAG_LIGHT_STATUS_BAR<br><br>    </em>if (nightModeFlags == Configuration.<em>UI_MODE_NIGHT_NO</em>) {<br>        <em>decorView</em>.<em>systemUiVisibility </em>= flags<br>    }<br>    <em>window</em>.<em>statusBarColor </em>= yourColorDay<br>}else<br>    <em>window</em>.<em>statusBarColor = yourColorNight</em></pre><h3><strong>Applying Dark mode</strong></h3><pre>AppCompatDelegate<br>.setDefaultNightMode(AppCompatDelegate.<em>MODE_NIGHT_YES</em>) // night mode</pre><pre>AppCompatDelegate<br>.setDefaultNightMode(AppCompatDelegate.<em>MODE_NIGHT_NO</em>) // day mode</pre><pre>//this will follow system settings (from notification bar)<br>AppCompatDelegate<br>.setDefaultNightMode(AppCompatDelegate.<em>MODE_NIGHT_FOLLOW_SYSTEM</em>)</pre><h3><strong>And of course one example</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/216/1*7A0M8GaeG16Wn6BzG-VsWg.gif" /><figcaption>Final result</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8a62d51092d" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/daynight-applying-dark-mode-without-recreating-your-app-c8a62d51092d">DayNight — Applying dark mode without recreating your app</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Single Activity with Fullscreen & Simple Fragments]]></title>
            <link>https://proandroiddev.com/single-activity-with-fullscreen-simple-fragments-fefe7f041765?source=rss-a6faec57c4db------2</link>
            <guid isPermaLink="false">https://medium.com/p/fefe7f041765</guid>
            <category><![CDATA[android-ui]]></category>
            <category><![CDATA[android-fragment]]></category>
            <category><![CDATA[fullscreen]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Jamshid Mamatkulov]]></dc:creator>
            <pubDate>Fri, 18 Sep 2020 10:48:04 GMT</pubDate>
            <atom:updated>2020-10-26T13:30:14.804Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*9DrGZk1qpT-7lEeV9qvTyA.png" /></figure><h3><strong>Single Activity</strong></h3><p>Recently Google have suggested that it’s better to use single activity for your applications. But what if your designer say that one UI should be on fullscreen, while another in simple mode, without drawing over status bar. Then for resolving this issue we will create one more Activity for Fullscreen and one Activity with Fragments for simple UI.</p><p>But with the help of Window insets you can easily do it on Fragments too and avoid using Activities and keep using Single Activity pattern.</p><h3><strong>systemUiVisibility</strong></h3><p>For rescuing us <em>systemUiVisibility </em>has been implemented. For setting UI visibility we have:</p><p><em>SYSTEM_UI_FLAG_VISIBLE, SYSTEM_UI_FLAG_LOW_PROFILE, SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_IMMERSIVE, SYSTEM_UI_FLAG_IMMERSIVE_STICKY, SYSTEM_UI_FLAG_LIGHT_STATUS_BAR, SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION</em></p><p>From these flags we only use two of them <em>SYSTEM_UI_FLAG_LAYOUT_STABLE SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION</em></p><p>For applying fullscreen mode within the app we need to apply it for our Single Activity then all our fragments will be in fullscreen mode, for this we have to call decorView’s setSystemUiVisiblity in our Activity</p><pre><em>window</em>?.<em>apply </em><strong>{<br>    </strong><em>decorView</em>.<em>systemUiVisibility </em>=<br>        View.<em>SYSTEM_UI_FLAG_LAYOUT_STABLE </em>or<br>                View.<em>SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION<br></em><br>    if (Build.VERSION.<em>SDK_INT </em>&gt;= Build.VERSION_CODES.<em>M</em>) {<br>        var flags: Int = <em>decorView</em>.<em>systemUiVisibility<br>        </em>flags = flags or View.<em>SYSTEM_UI_FLAG_LIGHT_STATUS_BAR<br>        decorView</em>.<em>systemUiVisibility </em>= flags<em><br>    </em>}<em><br><br>    navigationBarColor </em>= Color.<em>WHITE<br></em><strong>}</strong></pre><p>If you can see I’ve implemented <em>SYSTEM_UI_FLAG_LIGHT_STATUS_BAR </em>too, this flag is responsible for coloring our status bar into light mode (default is black).</p><p>If we run our app we will get such result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*b1wK61IOA1al1Mj-_lYWFw.png" /></figure><p>As you can see we do not achieved fullscreen after applying systemUiVisibility on decorView, all because of our app have White color as colorPrimaryDark in colors.xml. All we need is to set Transparent status bar onResume in Fragment and return to white onDestroy for exiting from Fullscreen when Fullscreen Fragment has been closed.</p><pre>override fun onResume() {<br>    super.onResume()<br>    <em>activity</em>?.<em>window</em>?.<em>statusBarColor </em>= Color.<em>TRANSPARENT<br></em>}<br><br>override fun onDestroy() {<br>    super.onDestroy()<br>    <em>activity</em>?.<em>window</em>?.<em>statusBarColor </em>= Color.<em>WHITE<br></em>}</pre><p>After applying transparent status bar we will get our fullscreen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*f4u649hMP_aUhfYZuf4irA.png" /></figure><p>What if we open SimpleFragment</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*b1wK61IOA1al1Mj-_lYWFw.png" /></figure><p>As you can see our image in simple fragment was clipped by status bar and for resolving this issue Window insets come to save us. Inside onViewCreated of Fragment we will listen for</p><pre>view.setOnApplyWindowInsetsListener <strong>{ </strong>v, insets <strong>-&gt;<br>    </strong>v.<em>updatePadding</em>(top = insets.<em>systemWindowInsetTop</em>)<br>    insets<br><strong>}</strong></pre><p>This function will be invoked when System wants to draw something over our view, something is status bar and navigation bar. System says us to set padding for our view in order to avoid clipping. Also we need to call</p><pre>if (view.<em>isAttachedToWindow</em>) {<br>    ViewCompat.requestApplyInsets(view)<br>} else {<br>    view.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {<br>        override fun onViewAttachedToWindow(v: View) {<br>            v.removeOnAttachStateChangeListener(this)<br>            ViewCompat.requestApplyInsets(v)<br>        }<br><br>        override fun onViewDetachedFromWindow(v: View) = Unit<br>    })<br>}</pre><p>because sometimes window insets doesn’t invoked and we have to call it manually and our setOnApplyWindowInsetsListener will be invoked</p><p>After applying such padding from top we will get result which we have expected</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*MycbSB1bjfZsT1M0uvva9Q.png" /></figure><p>Finally we have got our Simple and Fullscreen mode working as expected.</p><p>There is also an issue with navigation bar, some devices have navigation bar some doesn’t. If you want to avoid overdrawing on navigation bar use bottom padding in your view in v.updatePadding inside setOnApplyWindowInsetsListener. Or if you want to overdraw set Transparent color to navigation bar with <em>navigationBarColor </em>inside window in activity.</p><p>For more information about Window insets I really suggest you to watch Chris Banes “Becoming a master window fitter” on youtube <a href="https://www.youtube.com/watch?v=_mGDMVRO3iE">https://www.youtube.com/watch?v=_mGDMVRO3iE</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fefe7f041765" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/single-activity-with-fullscreen-simple-fragments-fefe7f041765">Single Activity with Fullscreen &amp; Simple Fragments</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>