-
Notifications
You must be signed in to change notification settings - Fork 0
Lab 9
Let’s make our app look a little better by leveraging the Android resource system.
-
Define new Color resources to customize your app theme
- Define these colors within
res/values/colors.xml
- The actual color values don't matter much
- Define these colors within
-
Update the primary, and secondary colors of your app's theme using the newly created Color resources
- The theme should be defined within
themes.xml
- You likely will see 2 versions of
themes.xml
; one for light more and one for dark mode - Deploy your app to observe the updated theme
- The theme should be defined within
-
If you can, change your device to Dark Mode and redeploy your app
- Notice that it likely doesn't look how you might expect
-
Update the
values-night
version of your app's theme with your custom colors -
Add the following values to both the Light and Dark Themes
colorSurface
backgroundColor
-
Update each fragment so its background color uses
?backgroundColor
and pulls from the Theme- ex
android:background="?backgroundColor"
- ex
-
Download a custom png icon for the Twitter menu item in your
Toolbar
- Can find icons here https://www.flaticon.com/
-
Create a new set of icons from the downloaded Twitter image
- Right-click on
res
directory, and selectNew
->Image Asset
- For "Icon Type`, select "Action Bar and Tab Icons"
- For "Asset Type" select "Image"
- Select the desired Twitter image in the "Path" field
- Name your icon
ic_twitter
and complete the creation process - Update our menu item in
main_toolbar.xml
to show the icon in theToolbar
if there's room by addingapp:showAsAction="ifRoom"
- Right-click on
-
Replace all menu item strings with string resource values
- This requires replacing any hardcoded string in the menu file with string resources using
@string/<resource name>
- This requires replacing any hardcoded string in the menu file with string resources using
-
Apply the following text Styles to the
TextViews
inNoteDetailFragment
TextAppearance.MaterialComponents.Headline3
TextAppearance.MaterialComponents.Headline4
TextAppearance.MaterialComponents.Body1
- Create a custom app icon using the "Image Asset" creation wizard using an "Icon Type" of launcher
- Re-deploy your app to observe the new icon in your launcher.
Provide an alternative horizontal layout for CreateNoteFragment
and/or NoteDetailsFragment
.
To do this, you'll need to create alternative layout resources for the land
layout resource qualifier. Right-click res
, go to New
-> Android Resource File
and choose a layout resource type, and add the landscape
resource qualifier by selecting it, and clicking the >>
icon to move it into the applied qualifiers list.
Customize the typography of your app by setting custom text styles in your theme.
- Overview of App Resources
- Configuration-Based Resource Naming
- Themes vs Styles
- String Resources Docs
- Color Resources Docs
- Dimension Resources Docs
- Style Resources Docs
- Boolean Resources Docs
- Drawable Resources Docs
- MaterialComponents Theming Getting Started Guide
- Material.io Color System Guide
There are a lot of possible Themes to choose to apply to your application. The two flavors you're mostly likely to run across include:
- AppCompat
- MaterialComponents
When starting a new Android app, it's best these days to use the MaterialCompoents library, and by extension, to use Theme.MaterialComponents
as a starting point for your own custom app theme.
Check out the Getting started with Material Components for Android
README for more info.
Check out the Material.io Color tool
The colors applied to our application theme make up the default set of colors that our Views will pull from for their default styling.
This is especially true when using Views from the Material Components library which do a great job with default theming.
The Material.io site has some great resources for better understanding how individual Theme colors are used. A few of the most common colors include
-
colorPrimary
: The color displayed most frequently across your app’s screens and components -
colorPrimaryVariant
: A tonal variation of the primary color. For light-mode themes, this is usually a slightly darker variant ofcolorPrimary
-
colorOnPrimary
: A color that passes accessibility guidelines for text/iconography when drawn on top of the primary color. -
colorSecondary
: The secondary branding color for the app, usually an accented complement to the primary branding color.
If you want to use the Theme's current backgroundColor
property for you own View
, say for example the background of a Fragment
container, you can reference the property as android:background="?backgroundColor"