Design System
  • Get started
    • Figma
    • Web
    • iOS
    • Android
  • Design tokens
    • Primitive colors
    • Semantic colors
      • Background Colors
      • On Background Colors
      • Foreground Colors
      • Border Colors
      • Focus Colors
      • Link Colors
    • Migration in iOS
    • Migration in android
    • Migration in web
    • Migration in figma
      • Step 1 Theme Migration
      • Step 2 Library Migration
      • Step 3 Journey Migration
    • Value & cost of migration
    • Deprecated tokens
  • Theme
    • Global branding
    • Component styling
    • Apply a theme on android
    • Apply a theme on iOS
    • Apply a theme on web
    • Multi theming on android
    • Multi theming on iOS
    • Multi theming on web
    • Theming illustrations
    • Before 2024 09
      • Create A Theme
      • Apply A Theme On Android
      • Apply A Theme On iOS
      • Apply A Theme On Web
      • Multi Theming On Android
      • Multi Theming On iOS
      • Multi Theming On Web
  • Accessibility
    • Overview
    • Designer checklist
    • Developer checklist
  • Guides
    • Custom icons on web
    • Beta ui ang with cursor
  • Web components
    • Account number
    • Account selector
    • Alert
    • Amount
    • Animations
      • Cross Journey
      • In Journey
      • Expand Reveal
      • Scroll Service
    • Avatar
    • Badges
      • Badge
      • Badge Counter
    • Button
    • Card vendor
    • Chip
    • Collapsibles
      • Collapsible
      • Collapsible Card
      • Collapsible Accordion
    • Money protection
      • Status
      • Disclaimer
      • Banner
    • Dropdowns
      • Dropdown Menu
      • Dropdown Single Select
      • Dropdown Multi Select
      • Dropdown Panel
    • Ellipsis
    • File attachment
    • Forms
      • Amount Input
      • Input Checkbox
      • Checkbox Group
      • Currency Input
      • Input Datepicker
      • Input Email
      • Fieldset
      • Input Inline Edit
      • List Multiple Select
      • Input Phone
      • Input Password
      • Input Radio Group
      • Input Range
      • Switch
      • Select List
      • Input Timepicker
      • Input Text
      • Textarea
      • Input Validation
      • Input File
      • Input Number
    • Icon
    • Illustration
    • Infinite scroll
    • Item log
    • Layouts and navigation
      • Horizontal Layout
      • Vertical Layout
    • Keyboard click directive
    • Loaders
      • Loading Indicator
      • Load Button
    • Locale selector
    • Logo
    • Modal
    • Mode header
    • Notification
    • Option list
    • Pagination
    • Page header
    • Payment card
    • Period selector
    • Product items
      • Basic Account
      • Savings Account
      • Current Account
      • Investment Account
      • Credit Card
      • Debit Card
      • Loan
      • Term Deposit
    • Product selector
    • Progress tracker
    • Progressbar
    • Rich text editor
    • Search box
    • States
      • Action Status
      • Empty State
      • Common Error State
    • Stepper
    • Css utilities
      • Bb Block
      • Bb Button Bar
      • Bb Card
      • Bb Container
      • Bb Display
      • Bb Inline Stack
      • Bb Layout Horizontal Navigation
      • Bb Layout Horizontal
      • Bb Layout
      • Bb Stack
      • Bb State Container
      • Bb Tabs Container
      • Bb Toolbar
      • Bb Vertical Tabs Container
    • Tab
    • Table
    • Tooltip
    • Tracker
    • Value diff
    • Universal header
  • Web formatters
    • Account number
    • Date
    • IBAN
    • Payment card number
    • Phone number
  • Mobile components
    • Alert
    • Amount
    • Async emblem
    • Avatar
    • Badge
    • Badge counter
    • Button
    • Button group
    • Card
    • Chip
    • Emblem
    • Floating action button
    • Forms
      • Address Form
      • Address Preview
      • Country Selector
      • Amount Input
      • Checkbox
      • Datepicker
      • Form Label
      • Phone Input
      • Password Input
      • Switch
      • Text Area
      • Text Input
    • Icon
    • Loading indicator
    • Link
    • Logo view
    • Navigation controller
    • Page control
    • Payment card
    • Product number display formatter
    • Progress bar
    • Separator
    • Search bar
    • Shimmer view
    • Slider
    • Snackbar
    • State view
    • Summary stack
    • Tab header
    • Toggle button

Multi Theming On Android

Getting started

Before diving further into this guide, you should be familiar with:

  • Global branding
  • Apply a theme to Android

Preparing the theme

After exporting from Figma the new theme, you should have an extra entry available in your theme.xml file. If you have any doubts about how to achieve this, please review the Apply a theme to Android guide again.

Switching themes

Next, we need to implement the logic for switching a theme. The following are suggestions and should not restrict the implementation and architecture of your application.


Step 1

Create a Dynamic Theme file in your project

Copy the following code and add it into your application.

        
            fun AppCompatActivity.selectedTheme() = themePreferences.getInt(ThemeResIdKey, Int.MAX_VALUE)
            fun AppCompatActivity.setDynamicThemeIfApply() {
            val themeResId = themePreferences.getInt(ThemeResIdKey, Int.MAX_VALUE)
            if (themeResId != Int.MAX_VALUE) setTheme(themeResId)
            observeThemeChanges()
            }
            fun AppCompatActivity.setThemeTo(@StyleRes themeResId: Int) {
            themePreferences.edit(commit = true) { putInt(ThemeResIdKey, themeResId) }
            }
            fun AppCompatActivity.setThemeToDefault() {
            themePreferences.edit(commit = true) { putInt(ThemeResIdKey, Int.MAX_VALUE) }
            }
            private fun AppCompatActivity.observeThemeChanges() {
            lifecycleScope.launch { themePreferences.selectedThemeFlow.collect { recreate() } }
            }
            val AppCompatActivity.themePreferences: SharedPreferences
            get() = getSharedPreferences(ThemePreferencesKey, Context.MODE_PRIVATE)
            private val SharedPreferences.selectedThemeFlow
            get() = callbackFlow {
                val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
                    if (ThemeResIdKey == key) trySend(getInt(key, /* defValue = */ Int.MAX_VALUE))
                }
                registerOnSharedPreferenceChangeListener(listener)
                awaitClose { unregisterOnSharedPreferenceChangeListener(listener) }
            }
            private const val ThemePreferencesKey = "theme_preferences"
            private const val ThemeResIdKey = "theme_id"
        
    



Step 2

Update your theme at runtime

At any point you can call the function setThemeTo(resId) and pass the theme resource id as parameter, or in case you want to use the default theme defined in your AndroidManifest.xml file, you can call the function setThemeToDefault().

    
      if (selectedTheme() == Int.MAX_VALUE) setThemeTo(themeResId =
      R.style.AppTheme_Premium) else setThemeToDefault()
    
  



On this page
Getting Started
Preparing the Theme
Switching Themes
©2025 All rights reserved
Terms and LegalPrivacy Policy

Cookies on Backbase

This website uses cookies to enhance your browsing experience, analyze the traffic, and for marketing purposes. All Google Analytics cookies are anonymized. By clicking 'Accept' you accept the use of all cookies as described in our privacy-statement.