创建style
- 初时化style
static lv_style_t style;
lv_style_init(&style);
- 设置背景颜色
lv_style_set_bg_color(&style, lv_palette_main(LV_PALETTE_GREEN));
- 设置边框颜色
lv_style_set_border_color(&style, lv_palette_lighten(LV_PALETTE_GREEN, 3));
- 设置边框宽度
lv_style_set_border_width(&style, 3);
- 创建obj对象
lv_obj_t* obj = lv_obj_create(lv_scr_act());
- 添加style到obj对象
lv_obj_add_style(obj, &style, 0);
- 使用Local style修改背景色
lv_obj_set_style_bg_color(obj, lv_palette_main(LV_PALETTE_ORANGE), LV_PART_MAIN);
- 居中显示
lv_obj_center(obj);
完整代码,仅供参考
static void lv_example_style_12(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_bg_color(&style, lv_palette_main(LV_PALETTE_GREEN));
lv_style_set_border_color(&style, lv_palette_lighten(LV_PALETTE_GREEN, 3));
lv_style_set_border_width(&style, 3);
lv_obj_t* obj = lv_obj_create(lv_scr_act());
lv_obj_add_style(obj, &style, 0);
/*Overwrite the background color locally*/
lv_obj_set_style_bg_color(obj, lv_palette_main(LV_PALETTE_ORANGE), LV_PART_MAIN);
lv_obj_center(obj);
}
调用lv_example_style_12运行效果