新手入门
- 积分
- 15
- 金钱
- 15
- 注册时间
- 2020-4-21
- 在线时间
- 1 小时
|
1金钱
- #include "user/app.h"
- lv_obj_t* btn2;
- lv_obj_t* led;
- lv_obj_t* label;
- static void event_handler(lv_obj_t* obj, lv_event_t event)
- {
- if(event == LV_EVENT_VALUE_CHANGED)
- {
- if (lv_btn_get_state(btn2) != LV_BTN_STATE_RELEASED)
- {
- label = lv_label_create(btn2, NULL);
- lv_label_set_long_mode(label, LV_LABEL_LONG_EXPAND);
- lv_label_set_text(label, "ON");
- printf("led on\n");
- lv_led_on(led);
- }
- else
- {
- abel = lv_label_create(btn2, NULL);
- lv_label_set_long_mode(label, LV_LABEL_LONG_EXPAND);
- lv_label_set_text(label, "OFF");
- printf("led off\n");
- lv_led_off(led);
- }
- }
- }
- void my_application(void)
- {
- btn2 = lv_btn_create(lv_scr_act(), NULL);
- lv_obj_set_event_cb(btn2, event_handler);
- lv_obj_align(btn2, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
- lv_btn_set_checkable(btn2, true);
- lv_btn_set_fit(btn2, LV_FIT_NONE);
- //label = lv_label_create(btn2, NULL);
- //lv_label_set_text(label, "OFF");
- led = lv_led_create(lv_scr_act(), NULL);
- lv_led_toggle(led);
- lv_obj_align(led, NULL, LV_ALIGN_CENTER, 0, 120);
- }
复制代码
这是在visual studio 2019 上仿真使用的,按钮的效果是现实了,但是按钮上的文字不是我想要的效果,我想要实现的效果是,当按钮按下去的时候,按钮上显示“打开”,当按钮弹起来的时候,按钮上显示“关闭”,请问应该如何做,大佬们给点建议!!! |
|