How to change the color of a specific button on the keyboard?

Description

How to change the color of a specific button on the keyboard?

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

What LVGL version are you using?

8.0

What do you want to achieve?

Change the color of a specific button on the keyboard.

What have you tried so far?

I can change Button style using LV_PART_ITEMS
But I can’t change color of a specific button.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/
 kb = lv_keyboard_create(lv_scr_act());
 lv_obj_add_style(kb, &kb_Style, LV_PART_MAIN);
 lv_obj_add_style(kb, &kb_Style2, LV_PART_ITEMS);

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

I was looking for the same thing. Maybe someone needs too, I am giving the solution.

When you look at the file lv_keyboard.c, you can see that LV_BTNMATRIX_CTRL_CHECKED flag is added to these buttons in mapping arrays. So you have to add “checked flag” for styling. The code is given above would be like:

/*You code here*/
 kb = lv_keyboard_create(lv_scr_act());
 lv_obj_add_style(kb, &kb_Style, LV_PART_MAIN);
 lv_obj_add_style(kb, &kb_Style2, LV_PART_ITEMS);
 lv_obj_add_style(kb, &kb_Style2, LV_PART_ITEMS | LV_STATE_CHECKED);
1 Like