πΉ Implementing Themes in Canvas Apps β A Complete Guide
π Introduction
A theme in Power Apps ensures consistent colors, fonts, and styles across all screens and components. By implementing themes, you can:
β
Enhance User Experience (UX)
β
Ensure Consistency Across Screens
β
Easily Modify the Look and Feel of the App
πΉ Step 1: Defining a Theme Using Variables
Instead of manually setting colors and fonts for each component, define a global theme using variables.
β Create a Global Theme on App Start
1οΈβ£ Select the App object in the Tree View
2οΈβ£ Set the OnStart
property to define a theme variable:
Set(AppTheme, {
PrimaryColor: RGBA(0, 122, 255, 1), // Blue
SecondaryColor: RGBA(255, 204, 0, 1), // Yellow
BackgroundColor: RGBA(240, 240, 240, 1), // Light Gray
TextColor: RGBA(0, 0, 0, 1), // Black
FontFamily: "Segoe UI"
});
3οΈβ£ Click Run OnStart to apply the theme.
π Now, the theme variables are available throughout the app!
πΉ Step 2: Applying the Theme to Components
β
Set Button Colors Dynamically
1οΈβ£ Select a Button
2οΈβ£ Set the Fill
property:
AppTheme.PrimaryColor
3οΈβ£ Set the Color
(Text Color) property:
AppTheme.TextColor
π Now, all buttons will use the theme color!
β
Set Screen Background Color
1οΈβ£ Select a Screen
2οΈβ£ Set the Fill
property:
AppTheme.BackgroundColor
π Now, all screens will have a consistent background!
β
Set Font for All Labels
1οΈβ£ Select a Label
2οΈβ£ Set the Font
property:
AppTheme.FontFamily
π Now, text across the app follows the same font!
πΉ Step 3: Creating a Theme Selection Feature
To allow users to switch themes dynamically, use a Dropdown or Toggle control.
β Add a Dropdown for Theme Selection
1οΈβ£ Insert a Dropdown (Insert
β Dropdown
)
2οΈβ£ Set Items
property to:
["Light Theme", "Dark Theme"]
3οΈβ£ Set the OnChange
property:
If(
Dropdown1.Selected.Value = "Dark Theme",
Set(AppTheme, {
PrimaryColor: RGBA(33, 33, 33, 1), // Dark Gray
SecondaryColor: RGBA(200, 0, 0, 1), // Red
BackgroundColor: RGBA(20, 20, 20, 1), // Black
TextColor: RGBA(255, 255, 255, 1), // White
FontFamily: "Arial"
}),
Set(AppTheme, {
PrimaryColor: RGBA(0, 122, 255, 1), // Blue
SecondaryColor: RGBA(255, 204, 0, 1), // Yellow
BackgroundColor: RGBA(240, 240, 240, 1), // Light Gray
TextColor: RGBA(0, 0, 0, 1), // Black
FontFamily: "Segoe UI"
})
)
π Now, selecting “Dark Theme” will apply dark colors dynamically!
πΉ Step 4: Using Collections for Multiple Themes
For more flexibility, store themes in a collection.
β Define Theme Collection on App Start
ClearCollect(ThemeCollection,
{ Name: "Light Theme", PrimaryColor: RGBA(0, 122, 255, 1), BackgroundColor: RGBA(240, 240, 240, 1), TextColor: RGBA(0, 0, 0, 1) },
{ Name: "Dark Theme", PrimaryColor: RGBA(33, 33, 33, 1), BackgroundColor: RGBA(20, 20, 20, 1), TextColor: RGBA(255, 255, 255, 1) }
);
Set(CurrentTheme, First(ThemeCollection));
β
Allow Users to Select a Theme Dynamically
1οΈβ£ Insert a Dropdown
2οΈβ£ Set Items
property:
ThemeCollection.Name
3οΈβ£ Set OnChange
property:
Set(CurrentTheme, LookUp(ThemeCollection, Name = Dropdown1.Selected.Value))
4οΈβ£ Apply theme variables:
Button1.Fill = CurrentTheme.PrimaryColor
Screen1.Fill = CurrentTheme.BackgroundColor
Label1.Color = CurrentTheme.TextColor
π Now, users can select themes from a dropdown!
πΉ Step 5: Storing User Theme Preferences
β Save the Selected Theme in PowerApps Storage
Set(CurrentUserTheme, Dropdown1.Selected.Value);
SaveData(CurrentUserTheme, "UserTheme");
β Load User Preferences on App Start
Set(LoadedTheme, LoadData("UserTheme", true));
Set(CurrentTheme, LookUp(ThemeCollection, Name = LoadedTheme));
π Now, the app remembers the userβs last selected theme!
πΉ Step 6: Implementing Themed Components
β Creating a Reusable Themed Button Component
1οΈβ£ Click Insert β Select Component
2οΈβ£ Add a Button inside the component
3οΈβ£ Set the Fill
property:
AppTheme.PrimaryColor
4οΈβ£ Save and reuse the Themed Button in multiple screens!
π Now, updating the theme will automatically update all buttons!
πΉ Step 7: Best Practices for Theming
β
Use Global Variables for Easy Theme Management
β
Ensure High Contrast for Readability
β
Store User Preferences for a Personalized Experience
β
Test the Theme on Different Devices
β
Use Components to Apply Themes Consistently
πΉ Conclusion
Theming in Power Apps enhances branding, improves consistency, and makes UI management easier.
π‘ Key Takeaways:
β
Define global theme variables using Set()
.
β
Apply themes dynamically to buttons, screens, and labels.
β
Allow users to switch themes using dropdowns.
β
Store and load user preferences for a personalized experience.
β
Use components to ensure consistent theming.
Now, you’re ready to implement a professional theme in your Power Apps!