Currently, my app-component routes to a split-layout which then navigates to other pages. When I want to change the accent color in the settings page, I use the following workaround:
changeAccentColor() {
console.log('Accent-color changed to: ', this.selectedAccentColor);
document.body.style.setProperty('--accentColor', this.selectedAccentColor);
document.body.style.setProperty('--toggleHead', '#ffffff');
}
The accent color is applied like this:
<ion-toggle style='--handle-background-checked:var(--toggleHead); --background-checked:var(--accentColor)'>Toggle</ion-toggle>
and in other places like this:
.active-link {
--ion-text-color: var(--accentColor);
font-weight: bold;
}
While this method somewhat works, it feels like a hack to me because I am unable to utilize Ionic's standard color handling methods. Is there a way to directly change the primary color during runtime, and if not, what would be the best alternative?