创建style
- 初时化style
static lv_style_t style;
lv_style_init(&style);
- 设置倒角为15
lv_style_set_radius(&style, 15);
- 设置背景透明度为不透明
lv_style_set_bg_opa(&style, LV_OPA_COVER);
- 设置背景色为淡灰色
lv_style_set_bg_color(&style, lv_palette_lighten(LV_PALETTE_GREY, 3));
- 设置边框线宽为2
lv_style_set_border_width(&style, 2);
- 设置边框颜色为蓝色
lv_style_set_border_color(&style, lv_palette_main(LV_PALETTE_BLUE));
- 设置image重色着色为蓝色
lv_style_set_img_recolor(&style, lv_palette_main(LV_PALETTE_BLUE));
- 设置image重新着色透明度为50%
lv_style_set_img_recolor_opa(&style, LV_OPA_50);
- 设置transform angle
lv_style_set_transform_angle(&style, 300);
- 创建obj,添加style
lv_obj_t* obj = lv_img_create(lv_scr_act());
lv_obj_add_style(obj, &style, 0);
- 声明image变量
LV_IMG_DECLARE(img_cogwheel_argb);
- 设置image图片资源
lv_img_set_src(obj, &img_cogwheel_argb);
- 居中显示
lv_obj_center(obj);
完整代码,仅供参考
static void lv_example_style_6(void)
{
static lv_style_t style;
lv_style_init(&style);
/*Set a background color and a radius*/
lv_style_set_radius(&style,15);
lv_style_set_bg_opa(&style, LV_OPA_COVER);
lv_style_set_bg_color(&style, lv_palette_lighten(LV_PALETTE_GREY, 3));
lv_style_set_border_width(&style, 2);
lv_style_set_border_color(&style, lv_palette_main(LV_PALETTE_BLUE));
lv_style_set_img_recolor(&style, lv_palette_main(LV_PALETTE_BLUE));
lv_style_set_img_recolor_opa(&style, LV_OPA_50);
lv_style_set_transform_angle(&style, 300);
/*Create an object with the new style*/
lv_obj_t* obj = lv_img_create(lv_scr_act());
lv_obj_add_style(obj, &style, 0);
LV_IMG_DECLARE(img_cogwheel_argb);
lv_img_set_src(obj, &img_cogwheel_argb);
lv_obj_center(obj);
}
- 需要配置下,否则会编译不通过
- 修改image着色为红色
lv_style_set_img_recolor(&style, lv_palette_main(LV_PALETTE_RED));
- 效果图