Developing themes with style (Android Dev Summit '19)
Why Stack Overflow recommends it
Stack Overflow users link it as the official guidance on structuring Android themes, styles and dark mode resources, and as the source of theme attribute techniques.
Recommended by 3 people across 3 different months, 2019 to 2023.
What it is
A 41-minute Android Dev Summit 2019 session by Nick Butcher and Chris Banes of the Android team. It gives a crash course in Android themes and styles, then works through examples of Material theming and dark theme support.
What people said
Recommends Isai Damier · 2019-11 · Stack Overflow · on “Layout Attributes within Styles”
In our most recent Android Dev Summit, two of my colleagues gave a talk on how to use Theme & Style [this video] . We advice that you use Themes for View groups and their children and styles for simpler views. Perhaps your layout needs can be met by using Themes and then reserving styles for text appearances and such. Beyond that, efficacy should guide how you structure your style objects.
Recommends Mark Pazon · 2020-01 · Stack Overflow · on “Android Dark Theme - Best way to implements dark theme on application”
First up is the youtube video below pretty much tells you what the current best practices are with regards to theming. [this video] They talked about splitting your styles into themes.xml -> theme related styles styles.xml -> component related styles type.xml -> text appearances styles All your colors should then be in one colors.xml which lives in values . You will then have the following structure: values/themes.xml values/colors.xml values/type.xml values/styles.xml values-night/themes.xml In practice, I find that it is still hard to contain all the colors in just one colors.xml . I still create values-night/colors.xml as some colors don't necessarily fall into a style. See this in practice in
Recommends A. Patrik · 2021-04 · Stack Overflow · on “How to implement theme appearance setting like YouTube in your android studio project”
Here's a comprehensive description of how you might achieve that using XML layouts and styles: [LINK] If you're completely new to XML theming in Android, then watch this video first: [this video]
Cites gmk57 · 2020-04 · Stack Overflow · on “Get color value programmatically when it's a reference (theme)”
More universal way, which also retrieves default value for a `ColorStateList`: `@ColorInt fun Context.getThemeColor(@AttrRes attribute: Int) = obtainStyledAttributes(intArrayOf(attribute)).use { it.getColor(0, Color.MAGENTA) }` (from Nick Butcher [this video] )
Cites Niklas Dada · 2020-08 · Stack Overflow · on “AndroidX FragmentActivity incompatible with Dark/Night Mode Changes”
I searched around for a while and had to "learn it the hard way": FragmentActivity from androidx.fragment.app.FragmentActivity does NOT work together with the documented way to change themes. So for example: You switch from day-theme to night-theme via AppCompatDelegate.setDefaultNightMode() in the onCreate() of you App class (a class which extends the Application class) because the configuration is not persistent after closing/opening the app and to make sure the configuration change (which is triggered by setDefaultNightMode() ) is done before any activities are created. So far so good: I.E. An AppCompatActivity will be created using the preferred theme. BUT if you launch a FragmentActivit
Cites LoyalPotato · 2023-11 · Stack Overflow · on “DayNight mode not working for Presentation dialog on second screen”
Neither methods are what I wanted. For the first one, I'm just defining a subset of the theme for that specific component (`.CFS`) and it should inherit from the `Theme.MyApp` (I've set it with parent as that and still has the same behavior). The second one doesn't work as well, because I'm defining theme attributes [this video] and not style attributes.