I want to change the color of the label when I theme changes. The problem is that when I select the color as the primary color and when changing themes by calling the “lv_theme_xx_init” function with another primary color, this label does not change color, it remains the same. How can I make it change color according to the theme change?
The code :
void test_change_theme (void)
{
lv_obj_t * main_screen = lv_obj_create(NULL, NULL);
lv_scr_load(main_screen);
lv_theme_t * base_theme = lv_theme_get_act();
lv_theme_copy(&custom_theme,base_theme);
/*Add some dummy content*/
txt = lv_label_create(main_screen, NULL);
lv_label_set_text(txt, "Test\n\n");
lv_obj_align(txt, NULL, LV_ALIGN_IN_TOP_MID, 0, 45);
lv_style_init(&style1);
lv_style_set_text_color(&style1, LV_STATE_DEFAULT, lv_theme_get_color_primary());
lv_obj_add_style(txt, LV_LABEL_PART_MAIN, &style1);
}
static void event_btn_handler(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
char * pch = strstr(lv_label_get_text(label),"Tema 1");
if(pch != NULL)
{
lv_label_set_text(label, "Tema 2");
lv_theme_xx_init(LV_COLOR_GREEN, LV_COLOR_SILVER,
LV_THEME_GERTEC_FLAG_DARK,
&lv_font_montserrat_30, &lv_font_montserrat_18, &lv_font_montserrat_20, &lv_font_montserrat_14);
}
else
{
lv_label_set_text(label, "Tema 1");
lv_theme_xx_init(LV_COLOR_AQUA, LV_COLOR_GRAY,
LV_THEME_MATERIAL_FLAG_LIGHT,
&lv_font_montserrat_12, &lv_font_montserrat_14, &lv_font_montserrat_16, &lv_font_montserrat_18);
}
}
}