Set list button as pressed or checkable when it is created


I have a list which buttons are created dynamically. I need to set one of the buttons as selected / pressed

What MCU/Processor/Board and compiler are you using?

ESP32-SPI TFT/Arduino 1.8.13

What LVGL version are you using?


What do you want to achieve?

I want to be able to set one of the buttons as “selected” or “current” while creating the buttons.

What have you tried so far?

I’ve tried by set the button checkeable = true. did not work
lv_btn_set_checkable(list_btn, true);
I’ve tried to put the focus in one of the buttons… did not work

Is it possible to set a different theme or colour for a particular button while it is created?

Code to reproduce

 /*Add buttons to the list*/
    lv_obj_t * list_btn;
    lv_group_t * lvglGroup = lv_group_create();
    for(int i=0; i<node_length;i++){
    String scene = nodes[i]["name"].as<const char*>();
    sceneList[i] = value;  
    list_btn = lv_list_add_btn(list1, NULL, scene);
    lv_obj_set_event_cb(list_btn, event_handler);
    if(value == currentSceneStr){
      Serial.println("current button :");
//      lv_list_focus(list_btn, LV_ANIM_ON);
      lv_btn_set_checkable(list_btn, true);
    lv_group_add_obj(lvglGroup, list_btn);
    //  lv_list_set_anim_time(list1, 200);

Found: I forgot to add