效果一:按下对象后,背景颜色过渡为红色
![](https://i-blog.csdnimg.cn/blog_migrate/d078c1df0da5598a57dc1034a135eec0.gif)
代码实现
//1、设置样式的过渡描述(transition_dsc)
static const lv_style_prop_t props[] = {LV_STYLE_BG_COLOR,0};
static lv_style_transition_dsc_t trans_dsc;
lv_style_transition_dsc_init(&trans_dsc,props,lv_anim_path_linear,3000,0,0); //线性路径、过渡3S
//2、初始化样式
static lv_style_t style;
lv_style_init(&style);
lv_style_set_bg_color(&style,lv_color_hex(0xFF0000));
lv_style_set_transition(&style,&trans_dsc); //设置过渡
//3、使用样式
lv_obj_t *obj = lv_obj_create(lv_scr_act());
lv_obj_add_style(obj,&style,LV_STATE_PRESSED); //按下时切换效果