![]() ![]() Similar implementation can be used to specify most custom attributes you need for theme specific resource values. In order to tell Android to use different drawables for different app themes, we create custom attributes 1 that allow specifying reference to the correct drawable, and provide different drawable references as values for these custom attributes under different themes (the same way appcompat library provides custom attributes such as colorPrimary). ![]() A dark action bar expects light-color menu items, and vice versa. drawables used for action bar menu items. For certain cases a color may look okay in both dark and light theme.Īt this point, we should have a pretty decent dark theme for our app, except for some anomalies here and there, e.g. Try out your alternative theme by temporary switching android:theme for application in AndroidManifest.xml to see what extra colors/style you need to create. By convention, here we suffix alternative theme colors with Inverse. android:textColorPrimary for dark theme should be light, and for light theme should be dark. The two themes should have appropriate (different if applicable) values for base Android and appcompat theme attributes, e.g. Unfortunately, since our two themes extend two different base themes, we cannot share any common attributes (the same way a class in Java cannot extend two or more classes). Here we add a new dark theme called AppTheme.Dark, and for style and color consistency, we extend from appcompat’s theme Theme.AppCompat (a dark theme). ![]() Materialistic also employs a similar approach. So how should we specify resources for multiple themes? If we look at how resources are organized in appcompat, we will have a rough idea of how the Android team organize their theme specific resources. Unfortunately, this is not yet an option at the time of this post. values-dark for dark theme resources and values-light for light theme resources. Ideally, if we treat theme as a configuration, we should be able to specify theme-specific resources under a ‘theme-qualifier’ resources directory, e.g. In this blog post, we will continue that effort, creating another theme and allowing dynamic switching of themes during runtime. In the first part of this post, we have created a light theme and made initial preparation to support multiple themes. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |